我想在当前可见的幻灯片上添加一个额外的类,我没有太多关于jquery的知识,我正在通过以下代码来尝试它。
$(document).ready(function(){
$('#slider1').bxSlider({
pager: 'true'
});
$(currentSlide).addClass('active-slide');
return false;
});
答案 0 :(得分:10)
要在第一张可见幻灯片上添加课程,您必须调用onSliderLoad。然后使用onSlideAfter调用继续添加和删除active-slide类。
onSlideAfter: function (currentSlideNumber, totalSlideQty, currentSlideHtmlObject) {
$('.active-slide').removeClass('active-slide');
$('.bxslider>li').eq(currentSlideHtmlObject + 1).addClass('active-slide')
},
onSliderLoad: function () {
$('.bxslider>li').eq(1).addClass('active-slide')
},
答案 1 :(得分:5)
var slider=$('#slider1').bxSlider({
pager: 'true',
onBeforeSlide: function(currentSlide, totalSlides, currentSlideHtmlObject){
$('.pager').removeClass('active-slide');
$(currentSlideHtmlObject).addClass('active-slide');
// $('#sddf').html('<p class="check">Slide index ' + currentSlide + ' of ' + totalSlides + ' total slides has completed.');
}
});
答案 2 :(得分:4)
这是:
$('#slider1 ul').bxSlider({
pager: 'true',
onSliderLoad: function(currentIndex) {
$('#slider1').find('.bx-viewport').find('ul').children().eq(currentIndex + 1).addClass('active-slide');
},
onSlideBefore: function($slideElement){
$('#slider1').find('.bx-viewport').find('ul').children().removeClass('active-slide');
$slideElement.addClass('active-slide');
}
});
答案 3 :(得分:-1)
100%正常工作
$(document).ready(function(){
$('.bxslider1').bxSlider({
slideWidth: 280,
slideMargin: 20,
useCSS: false,
autoHover: false,
speed: 2000,
oneToOneTouch: true,
pager: 'true',
onSliderLoad: function(currentIndex) {
$('.bxslider1').find('.bx-viewport').find('ul').children().eq(currentIndex + 1).addClass('active-slide');
},
onSlideBefore: function($slideElement){
$('.bxslider1').find('.bx-viewport').find('ul').children().removeClass('active-slide');
$slideElement.addClass('active-slide');
}
});
});