Skip to content

Instantly share code, notes, and snippets.

@sniperwolf
Last active September 6, 2022 12:42
Show Gist options
  • Save sniperwolf/4655666 to your computer and use it in GitHub Desktop.
Save sniperwolf/4655666 to your computer and use it in GitHub Desktop.
Bounce Effect - Simple Bounce Effect using only jQuery (and not jQuery UI).
<div id="hopper"></div>
function Bounce(ele, times, distance, speed) {
for (var i = 0; i < times; i++) {
ele.animate({
marginTop: '-=' + distance
}, speed).animate({
marginTop: '+=' + distance
}, speed);
}
}
$('#hopper').on('click', function() {
Bounce($(this), 2, '20px', 400);
});
#hopper {
height: 150px;
width: 150px;
background-color: green;
margin-top: 50px;
margin-left: auto;
margin-right: auto;
-o-border-radius: 5px;
-webkit-border-radius: 5px;
-moz-border-radius: 5px;
border-radius: 5px;
}
@radscheit
Copy link

for-loop is missing the declaration of i.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment