var washer = document.querySelectorAll(".wmachine")[0]; var icon = document.querySelectorAll(".WGTicon")[0]; var start = document.querySelectorAll(".start")[0]; var stop = document.querySelectorAll(".stop")[0]; $(".instruct").hide(3000); function spin(){ num = Math.floor(Math.random()*1000)+26000; icon.style.cssText = "border-radius:50%;position:relative;top:-167px;left:-4px;-webkit-transform:rotatez("+num+"deg);-webkit-transition:-webkit-transform 10s;pointer-events:none;"; start.style.background = "lime"; stop.style.background = "grey"; } function reset(){ icon.style.cssText ="border-radius:50%;position:relative;top:-167px;left:-4px;-webkit-transform:rotatez("+num%360+"deg)"; start.style.background = "grey"; stop.style.background = "orangered"; } washer.onmouseover = spin; washer.onmouseout = reset;