HTML5 Data Bindings Support Product Page

Image dynamically assigned to the style property

Asked 05 Jan 2014 20:45:02
1
has this question
05 Jan 2014 20:45:02 Gianmario Colciago posted:
Please, how can I dynamically assign an image to the style property "background" as in this example?
style = "background: url (img/image1.jpg) no-repeat center;"
Thank you and best wishes for a Happy New Year.
Gianmario

Replies

Replied 06 Jan 2014 10:04:21
06 Jan 2014 10:04:21 Teodor Kuduschiev replied:
Hello,

Can you please describe a little more detailed what do you need to achieve? Is this image being filtered by any variable? Is it the same for all of the pages?
Replied 07 Jan 2014 17:05:49
07 Jan 2014 17:05:49 Gianmario Colciago replied:
In my test site I have the DIV below. The property "background" in the inline style has a static image (gallery1.jpg). My goal is to get in each repeated DIV a different background (gallery1.jpg, gallery2.jpg, gallery3.jpg, and so on ...).
Could you please suggest me the solution?
Thanks.


<div class="span4 room" onClick="dmxDataBindingsAction('selectCurrent','repeat1',this);dmxAnimate('#dettagli', {'opacity': 0}, {'opacity': 1, 'height': 500, 'paddingTop': 30, 'paddingBottom': 30}, {'duration': 700, 'easing': 'linear', 'queue': false});dmxAnimate('.nascosto', {'opacity': 0}, {'opacity': 1,'height': 'auto'}, {'duration': 10})" style="background: url(img/gallery1.jpg) no-repeat center;" >


<div class="span4 room" onClick="dmxDataBindingsAction('selectCurrent','repeat1',this);dmxAnimate('#dettagli', {'opacity': 0}, {'opacity': 1, 'height': 500, 'paddingTop': 30, 'paddingBottom': 30}, {'duration': 700, 'easing': 'linear', 'queue': false});dmxAnimate('.nascosto', {'opacity': 0}, {'opacity': 1,'height': 'auto'}, {'duration': 10})" style="background: url(img/gallery1.jpg) no-repeat center;" >


Replied 08 Jan 2014 10:31:18
08 Jan 2014 10:31:18 Teodor Kuduschiev replied:
Hello Gianmario,

I can recommend you to use the id binding in the image name. For example - for the id=1 you have gallery1.jpg, for id=2 -> gallery2.jpg etc.
So in the link you can use:
...style="background: url(img/gallery{{id}}.jpg) no-repeat center;"
where {{id}} is the record id of your data source.

Reply to this topic