Im trying to create a function in javascript/jquery that creates a cool animation to the selected object. Problem is, when I add more objects too it, it acts pretty weird.
I understand that this is because if i for example add 4 objects too it, the code runs 4 times. How do I change this so it only goes of once on all the selected objects?
The code:
function showPress(name) {
var top = "15";
var bottom = "20";
$(name).hide();
$(name).show(150, function() {
$(name).animate( {
"margin-top": "+="+top+"px",
"margin-left": "+="+bottom+"px"
}, 150, function() {
$(name).animate({
"margin-top": "-="+top+"px",
"margin-left": "-="+bottom+"px"
});
});
});
}
showPress("h1");
TL;DR: What is going on here and how can I fix it? (I've tried but failed)