标签:transform utf-8 tle eve rand doctype 函数 form src
<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8">
<title></title>
<style type="text/css">
div {
margin: 0;
padding: 0;
}
.container {
width: 600px;
height: 600px;
margin: 100px auto;
position: relative;
}
.zhen img{
position: absolute;
left: 50%;
top: 50%;
margin: -190px 0 0 -45px;
z-index: 10;
}
.pan img{
z-index: 1;
width: 100%;
height: 100%;
}
</style>
</head>
<body>
<div class="container">
<div class="zhen">
<img src="img/zhen.png" >
</div>
<div class="pan">
<img src="img/pan.png" >
</div>
</div>
<script type="text/javascript">
var zhen = document.getElementsByClassName(‘zhen‘)[0];
var pan = document.getElementsByClassName(‘pan‘)[0];
var ranNum = 0;
var bool = true;
zhen.onclick = function () {
if (bool) {
ranNum = Math.floor(Math.random()*360); // 随机转动的角度
panRotate(ranNum); // 转盘转动函数
bool = false;
}
}
function panRotate(deg) {
var num = 5*360 + deg;
pan.style.transform = ‘rotate(‘+num+‘deg)‘;
pan.style.transition = ‘all 3s‘;
}
pan.addEventListener(‘webkitTransitionEnd‘, function () {
bool = true;
pan.style.transform = ‘rotate(‘+ranNum+‘deg)‘;
pan.style.transition = ‘none‘;
})
</script>
</body>
</html>
标签:transform utf-8 tle eve rand doctype 函数 form src
原文地址:https://www.cnblogs.com/hjysunshine/p/12183010.html