Servus,
wenn ich mit der Maus auf meinem DIV war (mouseenter), soll es kurz "zappeln".
Dazu ändere ich einfach die Position meines divs mit margin.
Es geht auch aber nur die ersten paar male. Danach passiert einfach mal gar nichts mehr. Warum?
Hier der Code:
Gruß
D.
wenn ich mit der Maus auf meinem DIV war (mouseenter), soll es kurz "zappeln".
Dazu ändere ich einfach die Position meines divs mit margin.
Es geht auch aber nur die ersten paar male. Danach passiert einfach mal gar nichts mehr. Warum?
Hier der Code:
HTML:
// Shake presents on hover
// -------------------------
$('.shake').each(function(){
var elem = this;
$(this).mouseenter(
function(){
elem = this;
var timesRun = 0;
vibrateIndex = setInterval(function(){
timesRun++;
// Rumble only 15 times
if(timesRun > 15){
clearInterval(vibrateIndex);
// Set elem to orig position
$(elem).css({
'marginTop': '0',
'marginRight': '0',
'marginBottom': '0',
'marginLeft': '0'
});
}else{
// Set random positions
$(elem).css({
'marginTop': Math.round(Math.random() * 5) + 'px',
'marginRight': Math.round(Math.random() * 5) + 'px',
'marginBottom': Math.round(Math.random() * 5) + 'px',
'marginLeft': Math.round(Math.random() * 5) + 'px'
});
}
}, 2);
}
);
});
Gruß
D.