jQuery Slider - 如何为每个图像设置不同的时间?
我试图让每个图像显示不同的时间量,并认为我可以使用循环插件,但似乎无法让它工作,这里所有代码
jQuery
$(document).ready(function(){
$('.slideshow ').cycle({
fx: 'fade',
speed: 'fast',
timeoutFn: function () {
return parseInt($(".slideshow img").attr('data-duration')) ;
}
});
});
HTML
<div class="slideshow">
<img data-duration="5400" src="beach1.jpg" width="200" height="200" />
<img data-duration="50" src="beach2.jpg" width="200" height="200" />
<img data-duration="50" src="beach3.jpg" width="200" height="200" />
<img data-duration="50" src="beach4.jpg" width="200" height="200" />
<img data-duration="50" src="beach5.jpg" width="200" height="200" />
</div>
我做错了什么?
感谢您的帮助:)
利亚姆
I am trying to get each image to have a different amount of time shown and thought I could use the cycle plugin but cant seem to get it to work, here all the code
jQuery
$(document).ready(function(){
$('.slideshow ').cycle({
fx: 'fade',
speed: 'fast',
timeoutFn: function () {
return parseInt($(".slideshow img").attr('data-duration')) ;
}
});
});
HTML
<div class="slideshow">
<img data-duration="5400" src="beach1.jpg" width="200" height="200" />
<img data-duration="50" src="beach2.jpg" width="200" height="200" />
<img data-duration="50" src="beach3.jpg" width="200" height="200" />
<img data-duration="50" src="beach4.jpg" width="200" height="200" />
<img data-duration="50" src="beach5.jpg" width="200" height="200" />
</div>
what am I doing wrong?
Thanks for any help :)
Liam
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(3)
您对
$(".slideshow img")
的调用匹配所有五个图像,并且 attr( ) 将始终返回第一个的data-duration
。您需要使用传递给 timeoutFn() 的参数:
请注意,返回
timeoutFn()
的值以毫秒表示,而不是秒。Your call to
$(".slideshow img")
matches all five images, and attr() will always return thedata-duration
of the first one.You'll need to use the arguments passed to timeoutFn() instead:
Note that the return value of
timeoutFn()
is expressed in milliseconds, not seconds.timeoutFn 回调会传递多个参数:当前幻灯片、下一张幻灯片、选项和前进标志。您可以更新
timeoutFn
函数来查看当前幻灯片:参考:http ://jquery.malsup.com/cycle/options.html
The
timeoutFn
callback is passed several arguments: current slide, next slide, options, and a forward flag. You can update yourtimeoutFn
function to look at the current slide:Reference: http://jquery.malsup.com/cycle/options.html
当前幻灯片元素属性的引用效果更好:
Referrer to the attributes of the current slide element works better: