Breaking

Followers

Sunday, 28 May 2017

Set images as background in loop

Features:- Set Images as a background in parent div.

HTML:

<ul>
  <li class="bg0"> <img src="images/homebanner1.jpg" width="1349" height="700" alt=""> </li>
  <li class="bg1"> <img src="images/homebanner2.jpg" width="1349" height="700" alt=""> </li>
  <li class="bg2"> <img src="images/homebanner3.jpg" width="1349" height="700" alt=""> </li>
  <li class="bg3"> <img src="images/homebanner4.jpg" width="1349" height="700" alt=""> </li>
</ul>

jQuery:
$("ul li img").each(function(a){var b=$(this).attr("src");$("ul li.bg"+a).css("background-image","url("+b+")")});

No comments:

Post a Comment