Polymer 聚合:如何动态处理样式
嘿,我正在尝试创建一个简单的拖放。是否可以动态设置元素的样式。我的代码将更加明确:Polymer 聚合:如何动态处理样式,polymer,Polymer,嘿,我正在尝试创建一个简单的拖放。是否可以动态设置元素的样式。我的代码将更加明确: <link rel="import" href="../bower_components/polymer/polymer.html"> <dom-module id="wireframe-view"> <template> <div on-tap="handleTap" style$=width:{{ width }}px; background
<link rel="import" href="../bower_components/polymer/polymer.html">
<dom-module id="wireframe-view">
<template>
<div on-tap="handleTap"
style$=width:{{ width }}px; background-color:red;
>Hello, World</div>
</template>
<script>
Polymer({
is: "wireframe-view",
handleTap: function() {
this.width = 200;
}
});
</script>
这将更改“我的样式”属性中的宽度:/如果属性值包含空格,则需要引号
style$="width:{{ width }}px; background-color:red";
如果属性值包含空格,则需要引号
style$="width:{{ width }}px; background-color:red";
下面是一种基于绑定数据属性的值动态更新样式的方法
<link rel="import" href="../bower_components/polymer/polymer.html">
<dom-module id="conditional-css-example">
<style>
#tapContainer {
width: 100px;
background-color:white;
}
#tapContainer[data-tap-status$="tapped"] {
width: 200px;
background-color:red;
}
</style>
<template>
<div id="tapContainer" data-tap-status$="[[tapStatus]]" on-tap="handleTap">Tap Me!</div>
</template>
<script>
Polymer({
is: "conditional-css-example",
properties: {
tapStatus: String;
},
handleTap: function() {
this.tapStatus='tapped';
}
});
</script>
下面是一种基于绑定数据属性的值动态更新样式的方法
<link rel="import" href="../bower_components/polymer/polymer.html">
<dom-module id="conditional-css-example">
<style>
#tapContainer {
width: 100px;
background-color:white;
}
#tapContainer[data-tap-status$="tapped"] {
width: 200px;
background-color:red;
}
</style>
<template>
<div id="tapContainer" data-tap-status$="[[tapStatus]]" on-tap="handleTap">Tap Me!</div>
</template>
<script>
Polymer({
is: "conditional-css-example",
properties: {
tapStatus: String;
},
handleTap: function() {
this.tapStatus='tapped';
}
});
</script>
这一点已经被问到并得到了回答:另一个问题是关于更改CSS变量的。我认为答案不适用于这个问题。这个问题已经被问过并回答过了:另一个问题是关于更改CSS变量的。我认为答案不适用于这个问题。等一下。。。。这在聚合物中有效吗?我不认为聚合物支持嵌入在其他文本中的绑定?最终添加的很好,是buggyIt吗?其实我自己也没用过。尽管我知道它的存在,但我坚持只绑定全部值而不是一部分。等一下。。。。这在聚合物中有效吗?我不认为聚合物支持嵌入在其他文本中的绑定?最终添加的很好,是buggyIt吗?其实我自己也没用过。尽管我知道它的存在,但我坚持只绑定全部值而不是一部分。