javascript - jQuery addClass loop starting from last-child up -
every thing works far every 500 milliseconds adds class next blockwrap element in line.
but want start last "blockwrap" element, add class , work way up. how can achieve this?
here html:
<div class="blockwrap"> <div class="blockimg"> <img src="img/download.jpg"> </div> </div> <div class="blockwrap"> <div class="blockimg"> <img src="img/download.jpg"> </div> </div> <div class="blockwrap"> <div class="blockimg"> <img src="img/download.jpg"> </div> </div>
here jquery loop:
$(document).ready(function(){ $(function () { var block = $('.blockwrap'); (function _loop(wrap) { block.eq(wrap).addclass('slidein'); settimeout(function () { _loop((wrap + 1) % block.length); }, 500); }(0)); }); });
thanks help.
use below code . pass block.length
param , deduct value -1 . add class bottom up
$(function () { var block = $('.blockwrap'); (function _loop(wrap) { block.eq(wrap).addclass('slidein'); settimeout(function () { _loop((wrap - 1) % block.length); }, 500); }(block.length)); });
Comments
Post a Comment