Javascript 防止跳过Flexslider中的元素
我正在使用滑块,我不希望用户能够跳过滑块中的图像。因此,我希望他们只能使用项目符号导航向前或向后单击1 以下是我迄今为止所做的尝试,但没有成功: 一段JavaScript,用于获取项目符号: 这让我到达了我想去的地方,但我无法阻止点击和幻灯片的变化 我的下一个方法是使用Flexslider的before回调,如下所示:Javascript 防止跳过Flexslider中的元素,javascript,jquery,flexslider,Javascript,Jquery,Flexslider,我正在使用滑块,我不希望用户能够跳过滑块中的图像。因此,我希望他们只能使用项目符号导航向前或向后单击1 以下是我迄今为止所做的尝试,但没有成功: 一段JavaScript,用于获取项目符号: 这让我到达了我想去的地方,但我无法阻止点击和幻灯片的变化 我的下一个方法是使用Flexslider的before回调,如下所示: $('.bulletgallery .flexslider').flexslider({ animation: "slide", before: function
$('.bulletgallery .flexslider').flexslider({
animation: "slide",
before: function(slider) {
var currentSlide = slider.currentSlide;
var nextSlide = slider.getTarget("next");
var prevSlide = slider.getTarget("prev");
// dead end, as currentSlide already points to the bullet clicked
}
});
但这不起作用,因为在回调中,currentSlide已经指向我单击的项目符号
那么,有什么想法吗?好吧,在远离这一点很久之后,我找到了一个解决方案,我对此感到非常高兴。为了可读性,我制作了很多变量:-
$(".bulletgallery .flex-control-paging li a").on("click", function(e) {
e.stopPropagation();
var $bullets = $(this).parent().siblings().andSelf();
var $me = $(this).parent();
var $active = $(".flex-active", $bullets).parent();
var meIndex = $bullets.index($me);
var activeIndex = $bullets.index($active);
if (meIndex == activeIndex) {
return;
}
var $slider = $(this).parents('.flexslider');
// if clicked on an item beyond or past the currently active slide, only move one
if (meIndex > activeIndex) {
$slider.flexslider('next');
} else {
$slider.flexslider('prev');
}
});
希望这对任何人都有帮助
$(".bulletgallery .flex-control-paging li a").on("click", function(e) {
e.stopPropagation();
var $bullets = $(this).parent().siblings().andSelf();
var $me = $(this).parent();
var $active = $(".flex-active", $bullets).parent();
var meIndex = $bullets.index($me);
var activeIndex = $bullets.index($active);
if (meIndex == activeIndex) {
return;
}
var $slider = $(this).parents('.flexslider');
// if clicked on an item beyond or past the currently active slide, only move one
if (meIndex > activeIndex) {
$slider.flexslider('next');
} else {
$slider.flexslider('prev');
}
});