我有一个 HTML 提示列表,该列表中的每个元素都在页面加载时隐藏,然后我尝试在指定时间后淡入 3 个随机提示,但是提示在不同时间淡入,尽管所有的时间设置相同,任何想法为什么会这样?
这是我的来源:
<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>