How do I bind an object such as i:
var Item = function() {
this.x = 10;
this.y = 10;
}
var i = new Item();
to a div
that has style " position: relative; left: {x}; top: {y}
"
Using http://rivetsjs.com/
You need to create a custom binder for that:
rivets.binders['style-*'] = function(el, value){
el.style.setProperty(this.args[0], value);
};
... then ...
<p rv-style-left="item.x" rv-style-top="item.top">
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.