帮助调用用于自动播放的 jQuery 函数的语法
如何让这个滑块自动播放?
答案如下:
<div class="slideshow"><ul>
<li><img src="lemons/1.jpg" alt="lemon" /></li>
<li><img src="lemons/2.jpg" alt="lemon tea" /></li>
<li><img src="lemons/3.jpg" alt="splashing lemon" /></li>
</ul></div>
<script type="text/javascript">
$(window).load(function () {
// start the slideshow
$('.slideshow').blinds();
var i = 0;
var j = 4; // this is hardcorded, one more than total images
// if you have a way of making j dynamic, please share
setInterval( function(){
if (i == j)
{
i = 1;
$('.slideshow').blinds_change(i);
i++;
} else {
$('.slideshow').blinds_change(i);
i++;
}
} , 3000 );
})
</script>
这是原始脚本的摘录(使用适用于 IE 8、7、6 等的 jQueryBlinds:http://www.littlewebthings.com/projects/blinds/):
<div class="slideshow"><ul>
<li><img src="lemons/1.jpg" alt="lemon" /></li>
<li><img src="lemons/2.jpg" alt="lemon tea" /></li>
<li><img src="lemons/3.jpg" alt="splashing lemon" /></li>
</ul></div>
<!-- change image links -->
<a href="#" class="change_link" onclick="$('.slideshow').blinds_change(0)">1</a>
<a href="#" class="change_link" onclick="$('.slideshow').blinds_change(1)">2</a>
<a href="#" class="change_link" onclick="$('.slideshow').blinds_change(2)">3</a>
<script type="text/javascript">
$(window).load(function () {
// start the slideshow
$('.slideshow').blinds();
})
</script>
How do I make this slider autoplay?
Here's the answer:
<div class="slideshow"><ul>
<li><img src="lemons/1.jpg" alt="lemon" /></li>
<li><img src="lemons/2.jpg" alt="lemon tea" /></li>
<li><img src="lemons/3.jpg" alt="splashing lemon" /></li>
</ul></div>
<script type="text/javascript">
$(window).load(function () {
// start the slideshow
$('.slideshow').blinds();
var i = 0;
var j = 4; // this is hardcorded, one more than total images
// if you have a way of making j dynamic, please share
setInterval( function(){
if (i == j)
{
i = 1;
$('.slideshow').blinds_change(i);
i++;
} else {
$('.slideshow').blinds_change(i);
i++;
}
} , 3000 );
})
</script>
This is the excerpt from the original script (using jQueryBlinds which work in IE 8,7,6, etc.: http://www.littlewebthings.com/projects/blinds/):
<div class="slideshow"><ul>
<li><img src="lemons/1.jpg" alt="lemon" /></li>
<li><img src="lemons/2.jpg" alt="lemon tea" /></li>
<li><img src="lemons/3.jpg" alt="splashing lemon" /></li>
</ul></div>
<!-- change image links -->
<a href="#" class="change_link" onclick="$('.slideshow').blinds_change(0)">1</a>
<a href="#" class="change_link" onclick="$('.slideshow').blinds_change(1)">2</a>
<a href="#" class="change_link" onclick="$('.slideshow').blinds_change(2)">3</a>
<script type="text/javascript">
$(window).load(function () {
// start the slideshow
$('.slideshow').blinds();
})
</script>
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
要使 j 动态化,您可以执行以下操作:
$('#sldeshow').children('ul').size();
To make j dynamic you can do:
$('#sldeshow').children('ul').size();
要设置定时事件,可以使用
setTimeout()
http://www .w3schools.com/js/js_timing.asp
To set timed events, you can use
setTimeout()
http://www.w3schools.com/js/js_timing.asp