Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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/

like image 799
user3590258 Avatar asked Dec 08 '25 09:12

user3590258


1 Answers

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">
like image 91
miniml Avatar answered Dec 09 '25 22:12

miniml