是否可以突出显示Flexslider轮播中的当前项目,因此我可以为活动的类添加一个类?
我使用Flexslider轮播的基本设置.现在我想有一个脚本,它将在视口内可见的每个幻灯片中添加活动状态.
这个例子我使用:
http://flexslider.woothemes.com/basic-carousel.html
我现在如何在start函数中获取Flexslider属性.当我给函数我可以要求的参数 – ul中的项目总数,它将移动多少项,以及将有多少页面调度.我不知道是否有可能编写一个formule来计算哪一个对于给定的变量是活跃的,所以我可以突出显示它们.
$('.flexslider').flexslider({
animation: "slide",
animationLoop: false,
slideshow: false,
itemWidth: 460,
itemMargin: 30,
minItems: 2,
maxItems: 6,
controlNav: false,
customDirectionNav: ".custom-direction li a",
start: function(slider) {
var pagingCount = slider.pagingCount;
var move = slider.move;
var visibleSlides = slider.visible;
var totalSlides = slider.count;
console.log(slider);
console.log(slider.move);
console.log(slider.update);
if (totalSlides) {
$('.slides li').addClass('active-slides');
};
// console.log(slider.count);
// console.log(slider.currentSlide);
}
});
我已经开始了,但不知道if语句或for循环应该如何完成.
有任何想法吗?
提前致谢.
最佳答案 使用事件开始和’之后’来处理这个问题.见下面的例子.
$('.flexslider').flexslider({
animation: "slide",
animationLoop: false,
slideshow: false,
itemWidth: 460,
itemMargin: 30,
minItems: 2,
maxItems: 6,
controlNav: false,
customDirectionNav: ".custom-direction li a",
start: function (slider) {
window.addCurrentSlidesClass(slider);
},
after: function (slider) {
window.addCurrentSlidesClass(slider);
}
});
window.addCurrentSlidesClass = function (slider) {
//debugger;
$('.flexslider li').removeClass("active-slides");
var startli = (slider.move * (slider.currentSlide));
var endli = (slider.move * (slider.currentSlide + 1));
for (i = startli + 1; i <= endli; i++) {
$('.flexslider li:nth-child(' + i + ')').addClass('active-slides');
}
}
<div class="flexslider carousel">
<div class="flex-viewport" style="overflow: hidden; position: relative;">
<ul class="slides" style="width: 2400%; transition-duration: 0.6s; transform: translate3d(0px, 0px, 0px);">
<li style="width: 210px; float: left; display: block;">
<img src="images/kitchen_adventurer_cheesecake_brownie.jpg" draggable="false">
</li>
<li style="width: 210px; float: left; display: block;">
<img src="images/kitchen_adventurer_lemon.jpg" draggable="false">
</li>
<li style="width: 210px; float: left; display: block;">
<img src="images/kitchen_adventurer_donut.jpg" draggable="false">
</li>
<li style="width: 210px; float: left; display: block;">
<img src="images/kitchen_adventurer_caramel.jpg" draggable="false">
</li>
<li style="width: 210px; float: left; display: block;">
<img src="images/kitchen_adventurer_cheesecake_brownie.jpg" draggable="false">
</li>
<li style="width: 210px; float: left; display: block;">
<img src="images/kitchen_adventurer_lemon.jpg" draggable="false">
</li>
<li style="width: 210px; float: left; display: block;">
<img src="images/kitchen_adventurer_donut.jpg" draggable="false">
</li>
<li style="width: 210px; float: left; display: block;">
<img src="images/kitchen_adventurer_caramel.jpg" draggable="false">
</li>
<li style="width: 210px; float: left; display: block;">
<img src="images/kitchen_adventurer_cheesecake_brownie.jpg" draggable="false">
</li>
<li style="width: 210px; float: left; display: block;">
<img src="images/kitchen_adventurer_lemon.jpg" draggable="false">
</li>
<li style="width: 210px; float: left; display: block;">
<img src="images/kitchen_adventurer_donut.jpg" draggable="false">
</li>
<li style="width: 210px; float: left; display: block;">
<img src="images/kitchen_adventurer_caramel.jpg" draggable="false">
</li>
</ul>
</div>
<ol class="flex-control-nav flex-control-paging">
<li><a class="flex-active">1</a>
</li>
<li><a class="">2</a>
</li>
<li><a class="">3</a>
</li>
</ol>
<ul class="flex-direction-nav">
<li class="flex-nav-prev"><a class="flex-prev flex-disabled" href="#" tabindex="-1">Previous</a>
</li>
<li class="flex-nav-next"><a class="flex-next" href="#" tabindex="-1">Next</a>
</li>
</ul>
<div class="flex-pauseplay"><a class="flex-pause">Pause</a>
</div>
</div>