Skip to content

Instantly share code, notes, and snippets.

Show Gist options
  • Save manekinekko/2063d3d782f39fc140c953448f0756f7 to your computer and use it in GitHub Desktop.
Save manekinekko/2063d3d782f39fc140c953448f0756f7 to your computer and use it in GitHub Desktop.
<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