Reputation: 877
How can I make it more elegant and universal? It works but I would like to have the margin added +52px to every next .alert occurrence.
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");
}
Any thoughts?
Upvotes: 2
Views: 70
Reputation: 382122
This :
$(".alert:visible").css('margin-top', function(i){return 52*i+'px'})
.delay(5000).slideUp("slow");
Upvotes: 5