Javascript旋转命运的两轮

Javascript Rotate two wheels of fortune

本文关键字:两轮 旋转 命运 Javascript      更新时间:2023-09-26

Beste,

今天我用javascript制作了一个旋转图像程序。

HTML:

<img id="image" src="http://static.kuikr.com/images/quikr_logo_f3.png" >   
<button onclick="start()">Start</button>
<button onclick="stop()">Stop</button>

Js:

var deg = 2; // starting
var rotation_diff = 30;
var rotation;
function start()
{
    rotation=1;    
    myFunction();
}
function stop()
{
    rotation=0;    
}
function myFunction() 
{
var img = document.getElementById("image");
img.style.webkitTransform = "rotate("+deg+"deg)";
img.style.transform = "rotate("+deg+"deg)";
img.style.MozTransform = "rotate("+deg+"deg)";
img.style.msTransform = "rotate("+deg+"deg)";
img.style.OTransform = "rotate("+deg+"deg)";
    if(rotation==1) {

       setTimeout("myFunction()",1000);   } 
deg = deg + rotation_diff;
}

你看,我已经做了一个启动和停止按钮,但我想要一个命运之轮。当它停在一个数字旁边时,我希望javascript能提醒这个数字。

感谢您抽出时间,

你可以计算出你的数字在命运之轮上的度数,然后使用它们。例如(伪代码(

if rotation is greater than 0 and less than 90 then score = 50
if rotation is greater than 90 and less than 180 ect.