var x = 0, y = 0; function m() { x += (Math.random() >= 0.4 ? 1 : -1 ) * (Math.random() * 5); y += (Math.random() >= 0.4 ? 1 : -1 ) * (Math.random() * 5); s = document.getElementById('search'); s.style.left = x; s.style.top = y; } window.onload = function () { setInterval(m, 200); };