我怎样才能让它更优雅和普遍?它的工作原理,但我想为每个下一个.alert事件添加+ 52px的余量.
var alerts = $(".alert");
if(alerts.is(":visible")) {
if(alerts.length > 1 ) {
alerts.eq(1).css('margin-top', '52px');
alerts.eq(2).css('margin-top', '104px');
alerts.eq(3).css('margin-top', '156px');
}
alerts.delay(5000).slideUp("slow");
}
Run Code Online (Sandbox Code Playgroud)
有什么想法吗?
这个 :
$(".alert:visible").css('margin-top', function(i){return 52*i+'px'})
.delay(5000).slideUp("slow");
Run Code Online (Sandbox Code Playgroud)