我有一个提示的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>