[英]carouFredSel add class to active slide
I'm trying to add a class of "active" to the current slide in carouFredSel, and I can't get it to work. 我正在尝试在carouFredSel的当前幻灯片中添加“活动”类,但无法使其正常工作。 The closest I could get it to work was to add it on the first slide, using
trigger("currentVisible")
, but it doesn't update. 我能使它工作的最接近的方法是使用
trigger("currentVisible")
将其添加到第一张幻灯片上,但是它不会更新。
Help! 救命! Thanks :)
谢谢 :)
So far, I used this function ( it doesn't work on page load though and it seems to be a lot of code for that simple task) Maybe someone has an idea how to simplify this and also make it work on page load 到目前为止,我已经使用了此功能(尽管该功能无法在页面加载时使用,并且似乎完成了该简单任务的代码很多)也许有人对如何简化此功能以及使其在页面加载时有效有所了解
function highlight( items ) {
items.filter(":eq(1)").addClass("active");
}
function unhighlight( items ) {
items.removeClass("active");
}
$('#foo').carouFredSel({
scroll : {
onBefore: function( data ) {
unhighlight( data.items.old );
},
onAfter : function( data ) {
highlight( data.items.visible );
}
},
});
Here's an update that should work fine on page load and scroll: Here are more details about the trigger event. 这是一个可以在页面加载和滚动上正常运行的更新: 这是有关触发事件的更多详细信息。
var $highlight = function() {
var $this = $("#foo");
var items = $this.triggerHandler("currentVisible"); //get all visible items
$this.children().removeClass("active"); // remove all .active classes
items.filter(":eq(1)").addClass("active"); // add .active class to n-th item
};
$('#foo').carouFredSel({
scroll : {
onAfter : $highlight
},
onCreate : $highlight
});
scroll : { onAfter : $highlight } 滚动:{onAfter:$ highlight}
solved my issue 解决了我的问题
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.