我有一个从0到9的随机数轮.轮子向下或向上旋转到落在随机数上.我怎样才能使轮子只旋转?(一旦达到9,下一个数字是0,1,2 ... 9,0,1,2),而不必有很多div.
function roll() {
var randomNum = Number((Math.random() * 100).toFixed(2));
var firstDigit = Number(Math.floor((randomNum) / 10 - 5));
var win = firstDigit;
if (win > 4) {
var rollm = win * 40 - 40 * 15;
document.getElementById("roll").style = "margin-top: " + rollm + "px ";
}
if (win < 4) {
var rollm = 180 - 40 * win - 380;
document.getElementById("roll").style = "margin-top: " + rollm + "px ";
}
if (win == 4) {
var rollm = 360;
document.getElementById("roll").style = "margin-top: -" + rollm + "px ";
}
}
body {
color: #fff;
}
#roll {
transition: .5s ease;
}
.ticker {
width: 0;
height: 0;
border-style: solid;
border-width: 15px 0px 15px 26px;
border-color: transparent #fff transparent;
margin: 0 -20px;
transform: translateY(-75px);
}
#roll {
width: 40px;
height: 360px;
background: #0077ee;
margin: 0 auto;
}
.roll-h {
width: 40px;
height: 120px;
margin: 0 auto;
overflow: hidden;
}
.shadow {
height: 40px;
margin: 0 auto;
transform: translateY(40px);
}
.black,
.his-h {
width: 40px;
height: 40px;
font-size: 20px;
line-height: 40px;
font-weight: 700;
text-align: center;
float: left;
}
.black {
background: black;
}
.floatleft {
float: left;
}
9
0
1
2
3
4
5
6
7
8
9
0