嗨我有一个轮盘赌轮正在使用Math.random()
生成它的旋转。但是在第一次使用后,它似乎不使用它应该使用的随机数。
var rand = ((Math.random() * 36) + 1);
var myInt = Math.floor(rand);
var posNum = Math.abs(myInt);
也似乎没有正确使用地板和腹肌功能,因为轮盘赌轮落在数字之间,有时会以错误的方式旋转。
以下是我的完整代码清单
loadTable() {
var addto = document.getElementsByTagName('td');
for (i = 0; i < addto.length; i++) {
addto[i].onclick = function() {
this.style.background = "url(\"Pictures/chip" + myChip + ".png\") no-repeat 100% 100%";
myChip++;
if (myChip == 12) {
myChip = 1;
}
};
}
document.getElementById('transparentWheel').onclick = function() {
var wheelDiv = document.getElementById('rouletteWheel');
var transparentDiv = document.getElementById('transparentWheel');
var rand = ((Math.random() * 36) + 1);
var myInt = Math.floor(rand);
var posNum = Math.abs(myInt);
var degree = posNum * 10;
var mydegree = 720 + degree;
wheelDiv.style.webkitTransform = 'rotate(' + mydegree + 'deg)';
wheelDiv.style.mozTransform = 'rotate(' + mydegree + 'deg)';
wheelDiv.style.msTransform = 'rotate(' + mydegree + 'deg)';
wheelDiv.style.oTransform = 'rotate(' + mydegree + 'deg)';
wheelDiv.style.transform = 'rotate(' + mydegree + 'deg)';
transparentDiv.style.webkitTransform = 'rotate(' + mydegree + 'deg)';
transparentDiv.style.mozTransform = 'rotate(' + mydegree + 'deg)';
transparentDiv.style.msTransform = 'rotate(' + mydegree + 'deg)';
transparentDiv.style.oTransform = 'rotate(' + mydegree + 'deg)';
transparentDiv.style.transform = 'rotate(' + mydegree + 'deg)';
}
}
#rouletteWheel {
border-radius: 180px;
margin: auto;
display: block;
position: relative;
margin: auto;
height: 300px;
width: 300px;
margin-top: 50px;
background: url(Pictures/roulette_wheel_2.jpg);
background-size: contain;
background-repeat: no-repeat;
-webkit-transition-duration: 8s;
-moz-transition-duration: 8s;
-ms-transition-duration: 8s;
-o-transition-duration: 8s;
transition-duration: 8s;
}
#transparentWheel {
position: absolute;
left: 0%;
top: 0%;
width: 100%;
height: 100%;
background: rgba(255, 255, 255, 0.0);
-webkit-transition-duration: 8s;
-moz-transition-duration: 8s;
-ms-transition-duration: 8s;
-o-transition-duration: 8s;
transition-duration: 8s;
}
#rouletteBall {
position: absolute;
left: 24%;
top: 26%;
width: 5%;
height: 5%;
background: url(Pictures/roulette_ball.jpg);
background-size: 100% 100%;
background-repeat: no-repeat;
border-radius: 10px;
}
function
<div id="rouletteWheel">
<div id="transparentWheel">
<div id="rouletteBall">
</div>
</div>
</div>
找到该页面