javascript - HTML changing images with JS interval -
i have code , need simple action: have 28 images in div , need change every 41ms.
i have html:
<div class="full_slider"> <img id="bgs_49" style="visibility: visible; display: block; opacity: 1;" src="images/background/10_00049.jpg" class="full_slider_child" alt="bg" /> <img id="bgs_50" src="images/background/10_00050.jpg" class="full_slider_child" alt="bg" /> <img id="bgs_51" src="images/background/10_00051.jpg" class="full_slider_child" alt="bg" /> <img id="bgs_52" src="images/background/10_00052.jpg" class="full_slider_child" alt="bg" /> <img id="bgs_53" src="images/background/10_00053.jpg" class="full_slider_child" alt="bg" /> <img id="bgs_54" src="images/background/10_00054.jpg" class="full_slider_child" alt="bg" /> <img id="bgs_55" src="images/background/10_00055.jpg" class="full_slider_child" alt="bg" /> <img id="bgs_56" src="images/background/10_00056.jpg" class="full_slider_child" alt="bg" /> <img id="bgs_57" src="images/background/10_00057.jpg" class="full_slider_child" alt="bg" /> <img id="bgs_58" src="images/background/10_00058.jpg" class="full_slider_child" alt="bg" /> <img id="bgs_59" src="images/background/10_00059.jpg" class="full_slider_child" alt="bg" /> <img id="bgs_60" src="images/background/10_00060.jpg" class="full_slider_child" alt="bg" /> <img id="bgs_61" src="images/background/10_00061.jpg" class="full_slider_child" alt="bg" /> <img id="bgs_62" src="images/background/10_00062.jpg" class="full_slider_child" alt="bg" />
and have js:
var bgs = ['49', '50', '51', '52', '53', '54', '55', '56', '57', '58', '59', '60', '61', '62', '61', '60', '59', '58', '57', '56', '55', '54', '53', '52', '51', '50', '49'] var pos = 1; setinterval(function() { pos = (pos+1) % bgs.length; pos_early = (pos-1) % bgs.length; slider_next = $("#bgs_" + pos); slider_prev = $("#bgs_" + pos_early); slider_prev.css({ 'visibility' : 'hidden', 'display' : 'none', 'opacity' : 0 }); slider_next.css({ 'visibility' : 'visible', 'display' : 'block', 'opacity' : 1 }); }, 41);
what need do, every 41ms previuos image should visibility: none, display: none, opacity: 0, , next image should visibility: visible, display: block , opacity: 1. how should it?
btw: code not working
try this
var cntmax = $('.full_slider').find('img').length; var cnt = 0; setinterval(function(){ $('.full_slider img:eq('+cnt+')').show().siblings().hide(); cnt==cntmax? cnt=0:cnt++; },41);
Comments
Post a Comment