如何公开和调用jQuery插件';公共方法
当到达最后一张幻灯片时,我被要求尝试停止此幻灯片放映 这是我需要修改的代码-额外的好处是从对象中获取幻灯片的数量如何公开和调用jQuery插件';公共方法,jquery,jquery-plugins,Jquery,Jquery Plugins,当到达最后一张幻灯片时,我被要求尝试停止此幻灯片放映 这是我需要修改的代码-额外的好处是从对象中获取幻灯片的数量 $(function(){ $('#slides').slides({ animationComplete: function(current) { // how to stop on the last slide: // a) get the number of slides from the object - called total in
$(function(){
$('#slides').slides({
animationComplete: function(current) {
// how to stop on the last slide:
// a) get the number of slides from the object - called total in the js
// b) call the stop() or pause() on the slideshow object
if (current>=????.total) {
????.stop();
}
},
preload: true,
.
.
});
});
这里是网站-我没有找到任何可以使用的示例,但是熟悉jQuery的人应该能够告诉我如何从以下位置调用此函数:
请告诉我您是如何找到该对象的,因为我从未尝试枚举jQuery方法 在普通JS中,我会做一些类似的事情
var txt = "";
for (var o in object) {
txt += '\n'+o+':'+object[o]
}
...
但是在这种情况下,我不确定如何访问slideshow对象,以及如何确定调用stop的方法。在stop()
方法中引用的“elem”是行为绑定到的元素;在本例中,$(“#幻灯片”)
。显然,脚本使用jQuery的data()
方法存储重复间隔。下面是一些工作代码,它使用相同的data()
方法检索该间隔,并使用图像数(减去两个按钮)来确定何时停止
注意:每次计算图像数量效率低下。总计数应该存储在一个变量中,但为了清晰起见,我将其保留在if()
语句中
$(function(){
$('#slides').slides({
animationComplete: function(current) {
// how to stop on the last slide
// a) get the number of slides from the object
// b) call the stop() or pause() on the slideshow object
if (current >= $("#slides img").length - 2) // Subtract Two arrows
clearInterval($('#slides').data('interval'));
},
preload: true,
preloadImage: 'http://slidesjs.com/img/loading.gif',
play: 5000,
pause: 2500,
slideSpeed: 600,
hoverPause: true
});
});
更新的JSFIDLE:在stop()
方法中引用的“elem”是行为绑定到的元素;在本例中,$(“#幻灯片”)
。显然,脚本使用jQuery的data()
方法存储重复间隔。下面是一些工作代码,它使用相同的data()
方法检索该间隔,并使用图像数(减去两个按钮)来确定何时停止
注意:每次计算图像数量效率低下。总计数应该存储在一个变量中,但为了清晰起见,我将其保留在if()
语句中
$(function(){
$('#slides').slides({
animationComplete: function(current) {
// how to stop on the last slide
// a) get the number of slides from the object
// b) call the stop() or pause() on the slideshow object
if (current >= $("#slides img").length - 2) // Subtract Two arrows
clearInterval($('#slides').data('interval'));
},
preload: true,
preloadImage: 'http://slidesjs.com/img/loading.gif',
play: 5000,
pause: 2500,
slideSpeed: 600,
hoverPause: true
});
});
更新的JSFIDLE:非常好。在数据方面,我添加了$(“.pagination”).remove()$(“.prev”).remove()$(“.next”).remove();要删除箭头和分页,请执行以下操作。在数据方面,我添加了$(“.pagination”).remove()$(“.prev”).remove()$(“.next”).remove();也要删除箭头和分页