<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8" />
<script src="http://code.jquery.com/jquery-1.9.1.js"></script>
<style type="text/css">
.slide{
position:absolute;
left:0px;
top:0px;
z-index:6;
display: none;
}
</style>
<script type="text/javascript">
$(window).load(function () {
var countx = $('.slide').length;
//alert("count " +countx);
var i;
var slidearray = new Array();
for (i = 0; i < countx; i++) {
slidearray[i] = i;
}
slidearray = shuffle(slidearray);
var t;
var pointx;
for (t = 0; t < slidearray.length; t++) {
pointx = slidearray[t];
action(pointx);
}
});
function action(id) {
var kex = "#slide" + id;
//alert(kex);
if (id == 0) {
x = 0;
} else {
x = id * 3500;
}
$(kex).delay(x).fadeIn(1000).delay(2500).fadeOut(1000);
}
function shuffle(array) {
var m = array.length,
t, i;
while (m) {
i = Math.floor(Math.random() * m--);
t = array[m];
array[m] = array[i];
array[i] = t;
}
return array;
}
</script>
</head>
<body>
<div id ="slide0" class="slide">Slide 0</div>
<div id ="slide1" class="slide">Slide 1</div>
<div id ="slide2" class="slide">Slide 2</div>
<div id ="slide3" class="slide">Slide 3</div>
<div id ="slide4" class="slide">Slide 4</div>
</body>
我正在尝试读取所有具有幻灯片类的 div,将其加载到数组中,打乱该数组,然后以打乱的顺序一次一个地淡化 div。
在我尝试淡入 div 之前,这一切都很好。它们总是淡入 0,1,2,3,4
即使你 shuffle 工作正常,我也不知道为什么它们不会在 shuffle 中消失