我有一个网站有一个包含一些图像的 div:
<div class="slideshow">
<img src="lib/images/grid/slideshow/a-960x305/a_pic1.jpg" width="960" height="305" alt="1" class="first" />
<img src="lib/images/grid/slideshow/a-960x305/a_pic2.jpg" width="960" height="305" alt="2" />
<img src="lib/images/grid/slideshow/a-960x305/a_pic3.jpg" width="960" height="305" alt="3" />
<img src="lib/images/grid/slideshow/a-960x305/a_pic4.jpg" width="960" height="305" alt="4" />
</div>
注意第一张图片有一个名为 first 的类名。这样页面通过 css 一次只显示一张图片:
这是 CSS:
/*begin slideshow*/
div.slideshow { margin:0 0 5px 0; /*height:305px;*/ } /*for the jQuery cycle plug in*/
div.slideshow img { display:none;}
div.slideshow img.first { display:block;}
.caption { text-align:center; font-weight:bold; color:#1F7FB6;}
/*end slideshow*/
我正在使用 jquery 循环库来循环浏览图像,如下所示:
<script type="text/javascript">
$(document).ready(function () {
$('.slideshow').cycle({
fx: 'fade', // choose your transition type, ex: fade, scrollUp, shuffle, etc...
timeout: 7000,
after: function () {
$('.caption').html(this.alt);
}
});
});
</script>
问题是页面当然总是从第一张图片开始,有没有办法随机化一点,这样它就可以开始随机图片而不是总是从 a_pic1.jpg
开始?
最佳答案
在 jQuery 循环中将 random
设置为 1
options
random: 0, // true for random, false for sequence (not applicable to shuffle fx)
$(document).ready(function () {
$('.slideshow').cycle({
fx: 'fade', // choose your transition type, ex: fade, scrollUp, shuffle, etc...
timeout: 7000,
after: function () {
$('.caption').html(this.alt);
},
random: 1 // <-- add this
});
});
关于jquery - 在 jQuery 中循环图像 - 随机化它?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/7081506/