jquery - How to align a rotating wheel to stop in center position not random position using javascripts? -


i trying create wheel on wordpress using javascript. have done making wheel , it's spinning randomly after click , stopping on random position.

i edit wheel function, stop on center position of each part of wheel. also, wheel not stop , repeat section again. in each click spin wheel stop in new section. , stop in center position of wheel. possible?

here have used spin wheel on wordpress

<img src="elevatingpolitics.com/wp-content/uploads/2016/10/ep-wheel.png" alt="" usemap="#linkwheel" width="500" height="auto" style="">   var img = document.queryselector('img'); img.addeventlistener('click', onclick, false);   function onclick() {     this.removeattribute('style');      var deg = 1500 + math.round(math.random() * 1500);      var css = '-webkit-transform: rotate(' + deg + 'deg);';      this.setattribute(         'style', css     ); } 

here wheel image sections using!!

thank in advance

you can simple math like:

var img = document.queryselector('img');  img.addeventlistener('click', onclick, false);      function onclick() {      this.removeattribute('style');        var deg =math.floor(math.random() * 360);         //split degrees in 8 values       var cad = deg%8;//get closest value       deg = cad*45;//set      var css = '-webkit-transform: rotate(' + deg + 'deg);';        this.setattribute(          'style', css      );  }
img { transition: transform 1s linear; vertical-align: middle; }
<img src="http://elevatingpolitics.com/wp-content/uploads/2016/10/ep-wheel.png" alt="" usemap="#linkwheel" width="500" height="auto" style="">

note: may want put center in different picture or remove text , use div on picture


Comments

Popular posts from this blog

aws api gateway - SerializationException in posting new Records via Dynamodb Proxy Service in API -

asp.net - Problems sending emails from forum -