Начинающий-Js-кодер,
жмите 'Enter' для старт/стопа анимации
<!DOCTYPE HTML>
<html>
<head>
<title>Untitled</title>
<meta charset="utf-8">
<style type="text/css">
#block{
position:absolute;
top:0;
left:0;
width:20px;
height:20px;
background:#000;
}
</style>
<script>
document.addEventListener('DOMContentLoaded', function() {
var b = document.querySelector('#block'), m = 0, n = .5, abracadabra = true;
function c()
{
if (abracadabra) m += n;
if(m == 100 || m == 0) n = -n;
b.style.marginLeft = m + 'px';
requestAnimationFrame(c)
}
requestAnimationFrame(c);
document.addEventListener('keyup', function(event) {
if(event.key == 'Enter') startStopAnimate(); });
function startStopAnimate() {abracadabra = !abracadabra}
});
</script>
</head>
<body>
<div id="block"></div>
</body>
</html>