Home Set Background Image as per dynamic content?
Reply: 1

Set Background Image as per dynamic content?

vjy tiwari
1#
vjy tiwari Published in 2017-09-14 10:00:09Z

How to set the background-image according to the dynamic content .

My html code like below

<div class="main-div">
     <div class="content-div">

     </div>
</div>
anu
2#
anu Reply to 2017-09-14 10:56:26Z

$(document).ready(function() {
  var imageUrl = 'https://www.stoneycreekhunting.co.nz/2_Key_Features_Rainwear_Insulation.png';

  $("<div class='dynamic-element'/>", {
    text: ""
  }).appendTo(".content-div");

  $('.dynamic-element').css({
    'background-image': 'url('+imageUrl+')',
    'background-size': 'cover',
    'height': '100%'
  });
});
.content-div {
  height: 100%;
}
<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script>
<div style="width:120px;height:120px;" class="main-div">
  <div class="content-div">

  </div>
</div>

You need to login account before you can post.

About| Privacy statement| Terms of Service| Advertising| Contact us| Help| Sitemap|
Processed in 0.303496 second(s) , Gzip On .

© 2016 Powered by cudou.com design MATCHINFO