简体   繁体   中英

How to bind style attribute top and left in rivet.js

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.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM