hyphens2
hyphens2

Reputation: 166

Rivetjs | How to bind image link to style="background-image:url()"

How i can bind item.image to style="background-image:url()"

<div rv-each-item="items">
   <div style="background-image:url()"></div>
</div>

As shown in this RIVETS Documentation

One-way binders

rivets.binders.color = function(el, value) {
  el.style.color = value
}

<button rv-color="label.color">Apply</button>

Upvotes: 0

Views: 189

Answers (1)

hyphens2
hyphens2

Reputation: 166

I fixed this issue

<div rv-each-item="items">
   <div rv-view-style="item.image"></div>
</div>

**JS**
rivets.binders['view-style'] = function(el, value) {
                el.style = 'background-image:url(https://xxx/' + value + ')';
            }

Upvotes: 0

Related Questions