我有一個提示的HTML列表,並且該列表中的每個元素都隱藏在頁面加載中,然後我嘗試在特定時間後淡出3個隨機提示,但是提示會在不同時間消失,相同的時間安排,任何想法爲什麼發生這種情況?JavaScript淡入淡出時間
這裏是我的源:
<script type="text/javascript">
this.randomtip = function() {
var pause = 4000;
var length = $("#tips li").length;
var temp = -1;
this.getRan = function() {
// get the random number
var ran = Math.floor((Math.random() * length) + 1);
return ran;
};
this.show = function() {
$("#tips li").fadeOut(800);
$("#tips li:nth-child(" + getRan() + ")").delay(1000).fadeIn(800);
$("#tips li:nth-child(" + getRan() + ")").delay(1000).fadeIn(800);
$("#tips li:nth-child(" + getRan() + ")").delay(1000).fadeIn(800);
};
show(); setInterval(show, pause);
};
$(document).ready(function() {
$("#tips li").hide();
randomtip();
});
</script>