I have a div and I am trying to move it right and left on page load using js to create a shaking movement.
My code:
<script type="text/javascript">
obj = document.getElementById('hs');
obj.style.position='relative';
function goRight(){
obj.style.right = 10px;
window.setTimeout(goLeft, 100);
}
function goLeft(){
obj.style.left = 10px;
window.setTimeout(goRight, 100);
}
window.onload =goRight;
</script>
But it doesn't work. The id of my div is hs.
The html is:
<div id="hs">
<h1>hs</h1>
<hr>
</div><
setTimeoutandsetInterval. You'll want to put some delay in there or this won't work.