[英]how to get last and first slide to make next and previous button active or disable accordingly
I have created this slider code... 我已经创建了此滑块代码...
trying to get first and last slide to make next and previous button active or disable accordigly... can anyone help me to get 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/ jsfiddle: http : //jsfiddle.net/GLSqS/1/
many thanks.. 非常感谢..
You can do it this way, instead of class for next and previous use id for each slide to hide that particular one instead of all, i leave that to you, 您可以这样操作,而不是使用每张幻灯片的下一个和上一个使用ID的类来隐藏特定的幻灯片而不是全部,我将其留给您,
I have done few changes to this code to show and hide, next and previous buttons: 我对该代码做了一些更改,以显示和隐藏下一个和上一个按钮:
if($('.thumbSlide li:first')){
$('.thumbSlide-prev').hide();
}
$(".thumbSlide-prev", this).click(function(){
var parentMove = $(this).parent().prev('.thumbSlide');
$(".thumbSlide-next").show();
if(parentMove.position().left < 0 && !$(".thumbSlide").is(":animated")){
parentMove.animate({left : "+=" + imageWidth + "px"});
}else{
$('.thumbSlide-prev').hide();
}
return false;
});
$(".thumbSlide-next", this).click(function(){
var parentMove = $(this).parent().prev('.thumbSlide');
//var parent=$(this).parent();
$(".thumbSlide-prev").show();
if(parentMove.position().left > stopPosition && !$(".thumbSlide").is(":animated")){
parentMove.animate({left : "-=" + imageWidth + "px"});
}else{
$(".thumbSlide-next").hide();
}
return false;
});
I have modified your code little bit. 我已经稍微修改了您的代码。 Try the 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;
});
});
}); });
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.