javascript - how to get last and first slide to make next and previous button active or disable accordingly -
i have created slider code...
trying first , last slide make next , previous button active or disable accordigly... can me it..
$(document).ready(function(){ $('.myslider-wrapper').each(function(){ // thumbslide var countslider = $('.thumbslide', this).length; if((".thumbslide").length){ // declare variables var totalimages = $(".thumbslide > li", this).length, imagewidth = $(".thumbslide > li:first", this).outerwidth(true), totalwidth = imagewidth * totalimages, visibleimages = math.round($(".thumbslide-wrap", this).width() / imagewidth), visiblewidth = visibleimages * imagewidth, stopposition = (visiblewidth - totalwidth/countslider); $(".thumbslide", this).width(totalwidth+10); } $(".thumbslide-prev", this).click(function(){ var parentmove = $(this).parent().prev('.thumbslide'); if(parentmove.position().left < 0 && !$(".thumbslide").is(":animated")){ parentmove.animate({left : "+=" + imagewidth + "px"}); } return false; }); $(".thumbslide-next", this).click(function(){ var parentmove = $(this).parent().prev('.thumbslide'); if(parentmove.position().left > stopposition && !$(".thumbslide").is(":animated")){ parentmove.animate({left : "-=" + imagewidth + "px"}); } return false; }); }); });
jsfiddle: http://jsfiddle.net/glsqs/1/
many thanks..
i have modified code little bit. try fiddle below.
$(document).ready(function(){ $('.myslider-wrapper').each(function(){ // thumbslide var countslider = $('.thumbslide', this).length; if((".thumbslide").length){ // declare variables var totalimages = $(".thumbslide > li", this).length, imagewidth = $(".thumbslide > li:first", this).outerwidth(true), totalwidth = imagewidth * totalimages, visibleimages = math.round($(".thumbslide-wrap", this).width() / imagewidth), visiblewidth = visibleimages * imagewidth, stopposition = (visiblewidth - totalwidth/countslider); $(".thumbslide", this).width(totalwidth+10); } $(".thumbslide-prev", this).click(function(){ var parentmove = $(this).parent().prev('.thumbslide'); if(parentmove.position().left < 0 && !$(".thumbslide").is(":animated")){ parentmove.animate({left : "+=" + imagewidth + "px"}); $(this).parent().find('.disable').removeclass('disable'); }else{ $(this).parent().find('.thumbslide-prev').addclass('disable'); } return false; }); $(".thumbslide-next", this).click(function(){ var parentmove = $(this).parent().prev('.thumbslide'); if(parentmove.position().left > stopposition && !$(".thumbslide").is(":animated")){ parentmove.animate({left : "-=" + imagewidth + "px"}); $(this).parent().find('.disable').removeclass('disable'); }else{ $(this).parent().find('.thumbslide-next').addclass('disable'); } return false; }); });
});
Comments
Post a Comment