如何让它更优雅,更通用?它有效,但我希望在下一个.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");
}
有什么想法?
答案 0 :(得分:5)
这:
$(".alert:visible").css('margin-top', function(i){return 52*i+'px'})
.delay(5000).slideUp("slow");