I have a lucky wheel, with a spinning arrow that rotates randomly. The problem is that sometimes the arrow barely spins when clicked on, because (for example) if the first click gives the number 400 the arrow will in fact rotate 400 degrees but if the second click gives 380 the arrow will just go back 20 degrees, meaning it will barely move. So I suppose I need a way to make the various clicks add up ( 1st click - random number; 2nd click - 1st click result + random number and so on).
My code is the following:
CSS
img {
transition: transform 2s ease-out;
}
HTML
<div>
<img src="34-200.png" />
</div>
JavaScript
<script>
var img = document.querySelector('img');
img.addEventListener('click', onClick, false);
function onClick() {
this.removeAttribute('style');
var deg = 500 + Math.round(Math.random() * 4000);
var css = 'transform: rotate(' + deg + 'deg);';
this.setAttribute(
'style', css
);
}
</script>
Help!