我试图在javascript中循环遍历类的每个元素,并在暂停一定时间后显示它。我有逻辑问题,但是由于jQuery调用的是类,而不是this的唯一实例,所以它会同时显示所有内容:
jQuery( document ).ready(function ($) {
$( ".fadein" ).hide();
$( ".fadein" ).each(function (index) {
$( "." + this.className ).delay(index * 800).fadeIn( "slow" );
});
});发布于 2013-11-05 19:02:44
每个循环已经设计成一次只给你一个元素。目标元素以“this”的形式传递,所以只需在“循环”中fadeIn当前元素,而不是每次都获取它们。
// Replace this
$( "." + this.className ).delay(index * 800).fadeIn( "slow" );
// with this
$( this ).delay(index * 800).fadeIn( "slow" );
// result:
$( ".fadein" ).each(function (index) {
$( this ).delay(index * 800).fadeIn( "slow" );
});https://stackoverflow.com/questions/19796675
复制相似问题