下面是一个更清洁和通用的方法来实现这样的效果: 检查出来上http://jsfiddle.net/BztLx/20/
逻辑特技依赖于fadeIn
的回调功能,并使用.eq()
作为在所选择的元素的迭代器。
<html>
<head>
<script src="http://code.jquery.com/jquery-latest.js"></script>
<script type="text/javascript">
$(document).ready(function() {
function sequentialFadeIn(selectorText, speed, display, callBack) {
display = typeof display !== 'undefined' ? display : "block";
var els = $(selectorText), i = 0;
(function helper() {
els.eq(i++).fadeIn(speed, helper).css("display", display);
if (callback && i === els.length) callback();
})();
}
sequentialFadeIn(".toBeFaddedIn", "slow", "inline-block", function() {
console.log("I am just an optional callback");
});
});
</script>
</head>
<body><style media="screen" type="text/css">
.hello {
background-color: blue;
height:50px;
width: 50px;
display: none;
}
</style>
<div class="hello toBeFaddedIn"></div>
<div class="hello toBeFaddedIn"></div>
<div class="hello toBeFaddedIn"></div>
<div class="hello toBeFaddedIn"></div>
<div class="hello toBeFaddedIn"></div>
</body></html>
如果在浏览器中没有Javascript,则不会淡入或其他类似效果。因此,在应用淡入效果的同时,不用担心javascript禁用的浏览器,您可以在noscript部分中显示静态内容。 – Atharva 2012-11-25 09:21:12
回答连续衰落的主要查询我试图在下面回答它。 – Atharva 2012-11-25 09:21:38