使用JQuery事件在Bootstrap幻灯片操作后显示文本

我想在Bootstrap中为每个图像(我有三个幻灯片)完成幻灯片操作后,在链接下方显示一个链接。 我试图使用slid.bs.carousel方法,它不起作用。 这是我正在使用的JQuery,如果您有任何建议,请告诉我 – 包含轮播的div是#sticksCarousel(而不是默认的’#myCarousel’)

$('#sticksCarousel').on('slid.bs.carousel', function() { alert("BALLS"); }); 

谢谢!

编辑:这是我对旋转木马的HTML …

 

HEY!

$('.carousel').carousel({ interval: 4000 }) $('#sticksCarousel').on('slid.bs.carousel', function() { alert("BALLS"); });

基本上我要做的是在每次旋转木马幻灯片操作完成时,在id“sticksCarouselMessage”下获取段落,现在它只是设置为’HEY’。 我正在使用javascript警报function作为测试,以查看引导方法slid.bs.carousel是否正在我的网站上工作,现在它不是。

更新:

这里我对所有HTML内容所做的更改……它仍然不起作用

     Untitled Document     body { background:url(img/body_bg.png) repeat; } .sticksNav { height:70px; } .headerImg{ margin-bottom:20px; }   $(document ).ready.(function() { $('.carousel').carousel({ interval: 4000 }); $('#sticksCarousel').on('slid.bs.carousel', function() { $("#sticksCarouselMessage").text("It worked!"); }); });   

 

HEY!

$(document ).ready.(function() { $('.carousel').carousel({ interval: 4000 }); $('#sticksCarousel').on('slid.bs.carousel', function() { $("#sticksCarouselMessage").text("It worked!"); }); });

我只想用id’sticksCarouselMessage更改p中的内容以显示“它工作了!” 在执行滑动动作之后。

在twitter bootstrap示例页面: http : //getbootstrap.com/javascript/#carousel ,此事件有效。

 $('.bs-example').on('slid.bs.carousel', function() { alert("BALLS"); }); 

您使用的是什么版本的Bootstrap? 早期版本的滑动事件有不同的名称。 如果您使用的是Bootstrap 3,那么还有其他一些问题,所以如果您可以发布有关如何调用轮播的更多信息,那可能有所帮助。

编辑:雅各布,您需要在文档中初始化轮播。已经:然后您可以注册事件。 例如。:

Bootstrap 3:

  

Bootstrap 2:

  

使用$('#featureRotator').bind('slide.bs.carousel', function (e) { console.log('slide event!'); });

并且工作正常。 它打印’幻灯片事件!’。 从我看到的,你在function(e)中缺少事件’e’。 尝试举办活动,看看是否有效。

注意’滑动’和’滑动’。 “幻灯片”发生在动画之前,然后“滑动”…因此您可以将代码添加到以下任一事件中……

 $('#featureRotator').bind('slide.bs.carousel', function (e) { console.log('slide event starts!'); }); $('#featureRotator').bind('slid.bs.carousel', function (e) { console.log('slide event finished!'); }); 
Interesting Posts