Created
October 1, 2018 14:36
-
-
Save manekinekko/2063d3d782f39fc140c953448f0756f7 to your computer and use it in GitHub Desktop.
This file contains hidden or 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
<style> | |
#content { | |
width: 27px; | |
height: 40px; | |
background: red; | |
position: relative; | |
border-radius: 50%; | |
line-height: 40px; | |
padding-left: 14px; | |
color: white; | |
} | |
</style> | |
<div id="content"> ♥ </div> | |
<button id="animateRight">Animate Right</button> | |
<script> | |
const animateRight = function() { | |
let tick = 0; | |
const content = document.querySelector('#content'); | |
const timer = setInterval(function(){ | |
if(tick < 200){ | |
content.style.left = tick + 'px'; | |
tick += 1; | |
} | |
else { | |
clearInterval(timer); | |
} | |
}, 1000/60); | |
}; | |
const click = function(){ | |
animateRight(); | |
}; | |
document.querySelector('#animateRight').addEventListener('click', click); | |
</script> |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment