Last active
September 6, 2022 12:42
-
-
Save sniperwolf/4655666 to your computer and use it in GitHub Desktop.
Bounce Effect - Simple Bounce Effect using only jQuery (and not jQuery UI).
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<div id="hopper"></div> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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); | |
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#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; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
for
-loop is missing the declaration ofi
.