Polymer({
is: 'cat-element',
_says: 'meow',
speak: function() {
console.log(this._says);
}
});
使用方法:
var cat1 = document.querySelector('cat-element');
cat1.speak();
var cat2 = document.createElement('cat-element');
cat2.speak();
绑定css或class属性:
Class and attribute manipulation
-
toggleClass(name, bool, [node])
. Toggles the named boolean class on the host element, adding the class ifbool
is truthy and removing it ifbool
is falsey. Ifnode
is specified, sets the class onnode
instead of the host element. -
toggleAttribute(name, bool, [node])
. LiketoggleClass
, but toggles the named boolean attribute. -
attributeFollows(name, newNode, oldNode)
. Moves a boolean attribute fromoldNode
tonewNode
, unsetting the attribute (if set) onoldNode
and setting it onnewNode
. -
classFollows(name, newNode, oldNode)
. Moves a class fromoldNode
tonewNode
, removing the class (if present) onoldNode
and adding it tonewNode
CSS transforms
-
transform(transform, [node])
. Applies a CSS transform to the specified node, or host element if no node is specified.transform
is specified as a string. For example:this.transform('rotateX(90deg)', this.$.myDiv);
-
translate3d(x, y, z, [node])
. Transforms the specified node, or host element if no node is specified. For example:this.translate3d('100px', '100px', '100px');