html+js
<!DOCTYPE html>
<html>
<head>
<meta http-equiv="content-type" content="text/html" charset="utf-8" />
<meta name="viewport" content="initial-scale=1.0,minimum-scale=1.0,maximum-scale=1.0,user-scalable=no" />
<title>Rotate</title>
<link href="css/style.css" rel="stylesheet">
</head>
<body>
<div class="rotate_wrap">
<img class="bg_img rotate_origin" id="i_bg" src="images/img1.png">
<img class="cont_img rotate_origin1" id="i_cont" src="images/img2.png">
</div>
<div class="btn" id="i_btn">开始</div>
<div class="btn1" id="i_back">退出</div>
<div class="overfloat" id="i_close_cont">
<div class="overfloat_cont">
<strong class="top_space">提交成功</strong>
<div><span id="i_time" class="font_red">5s</span> 后自动返回微信。</div>
<div id="i_close" class="btn">立即返回</div>
</div>
</div>
<script src="http://libs.baidu.com/jquery/1.9.0/jquery.min.js"></script>
<script type="text/javascript">
// 转盘样式,a:旋转角度,p:概率(1代表100%),t:需要显示的其它信息(文案or分享)
var result_angle = [{a:0,p:0.1,t:‘桃花朵朵开^_^‘},{a:45,p:0.1,t:‘哎呦,不错哦^_^‘},{a:90,p:0.1,t:‘天天开心呢^_^‘},{a:135,p:0.3,t:‘给姐笑一个^_^‘},{a:180,p:0.1,t:‘今天天气不错^_^‘},{a:225,p:0.1,t:‘心情大好哈哈^_^‘},{a:270,p:0.1,t:‘中奖五百万^_^‘},{a:315,p:0.1,t:‘打架你赢了^_^‘}];
var rotate = {
rotate_angle : 0, //起始位置为0
flag_click : true, //转盘转动过程中不可再次触发
calculate_result:function(type,during_time){//type:0,箭头转动,1,背景转动;during_time:持续时间(s)
var self = this;
type = type || 0; // 默认为箭头转动
during_time = during_time || 1; // 默认为1s
var rand_num = Math.ceil(Math.random() * 100); // 用来判断的随机数,1-100
var result_index; // 最终要旋转到哪一块,对应result_angle的下标
var start_pos = end_pos = 0; // 判断的角度值起始位置和结束位置
for(var i in result_angle){
start_pos = end_pos + 1; // 区块的起始值
end_pos = end_pos + 100 * result_angle[i].p; // 区块的结束值
if(rand_num >= start_pos && rand_num <= end_pos){ // 如果随机数落在当前区块,那么获取到最终要旋转到哪一块
result_index = i;
break;
}
}
var rand_circle = Math.ceil(Math.random() * 2) + 4; // 附加多转几圈,2-3
self.flag_click = false; // 旋转结束前,不允许再次触发
if(type == 0){ // 转动盘子
self.rotate_angle = self.rotate_angle - rand_circle * 360 - result_angle[result_index].a - self.rotate_angle % 360;
$(‘#i_bg‘).css({
‘transform‘: ‘rotate(‘+self.rotate_angle+‘deg)‘,
‘-ms-transform‘: ‘rotate(‘+self.rotate_angle+‘deg)‘,
‘-webkit-transform‘: ‘rotate(‘+self.rotate_angle+‘deg)‘,
‘-moz-transform‘: ‘rotate(‘+self.rotate_angle+‘deg)‘,
‘-o-transform‘: ‘rotate(‘+self.rotate_angle+‘deg)‘,
‘transition‘: ‘transform ease-out ‘+during_time+‘s‘,
‘-moz-transition‘: ‘-moz-transform ease-out ‘+during_time+‘s‘,
‘-webkit-transition‘: ‘-webkit-transform ease-out ‘+during_time+‘s‘,
‘-o-transition‘: ‘-o-transform ease-out ‘+during_time+‘s‘
});
}else{ // 转动指针
self.rotate_angle = self.rotate_angle + rand_circle * 360 + result_angle[result_index].a - self.rotate_angle % 360;
$(‘#i_cont‘).css({
‘transform‘: ‘rotate(‘+self.rotate_angle+‘deg)‘,
‘-ms-transform‘: ‘rotate(‘+self.rotate_angle+‘deg)‘,
‘-webkit-transform‘: ‘rotate(‘+self.rotate_angle+‘deg)‘,
‘-moz-transform‘: ‘rotate(‘+self.rotate_angle+‘deg)‘,
‘-o-transform‘: ‘rotate(‘+self.rotate_angle+‘deg)‘,
‘transition‘: ‘transform ease-out ‘+during_time+‘s‘,
‘-moz-transition‘: ‘-moz-transform ease-out ‘+during_time+‘s‘,
‘-webkit-transition‘: ‘-webkit-transform ease-out ‘+during_time+‘s‘,
‘-o-transition‘: ‘-o-transform ease-out ‘+during_time+‘s‘
});
}
// 旋转结束后,允许再次触发
setTimeout(function(){
self.flag_click = true;
// 告诉结果
alert(result_angle[result_index].t);
},during_time*1000);
}
}
$(document).ready(function(){
$(‘#i_btn‘).click(function(){
if(rotate.flag_click){ // 旋转结束前,不允许再次触发
rotate.calculate_result(1,1);
}
});
var t=5;//5秒后返回微信
function f_t(){
setTimeout(function(){
t--;
$("#i_time").html(t+"s");
f_t();
},1000)
}
$(‘#i_back‘).click(function(){
$("#i_close_cont").show();
f_t();
});
$(‘#i_close‘).click(function(){
$("#i_close_cont").hide();
});
});
</script>
</body>
</html>
css 代码:
html,body,div,img,a{
margin:0;
padding:0;
font:normal normal 300 16px/1.5 "微软雅黑",arial,verdana;
}
.btn,.btn:hover.btn:visited{
color:#ffffff;
background-color:#fd5b78;
margin:10px auto;
display:block;
text-align: center;
width:240px;
height:40px;
line-height:40px;
border:1px solid #DE3163;
border-radius:4px;
cursor:pointer;
}
.btn:active{
background-color:#e46084;
}
.btn1,.btn1:hover.btn1:visited{
color:#ffffff;
background-color:#008573;
margin:10px auto;
display:block;
text-align: center;
width:240px;
height:40px;
line-height:40px;
border:1px solid #00755E;
border-radius:4px;
cursor:pointer;
}
.btn1:active{
background-color:#00755E;
}
.rotate_wrap{
width: 90%;
max-width: 300px;
height: 300px;
margin: 20px auto 50px;
position:relative;
}
.bg_img{
width:100%;
position:absolute;
top:0;
left:0;
}
.cont_img{
width: 31px;
position: absolute;
top: 72px;
left:135px;
}
.rotate_origin{
transform-origin: 50% 50%;
-ms-transform-origin:50% 50%;
-webkit-transform-origin:50% 50%;
-moz-transform-origin:50% 50%;
-o-transform-origin:50% 50%;
}
.rotate_origin1{
transform-origin: 50% 85%;
-ms-transform-origin:50% 85%;
-webkit-transform-origin:50% 85%;
-moz-transform-origin:50% 85%;
-o-transform-origin:50% 85%;
}
.overfloat{
position:fixed;
top:0;
left:0;
width:100%;
height:100%;
background-color:rgba(1,1,1,0.5);
z-index:9;
display:none;
}
.overfloat_cont{
position:fixed;
top:50%;
left:50%;
width:318px;
height:160px;
margin-left:-159px;
margin-top:-80px;
border-radius: 4px;
text-align:center;
font-size:20px;
color:#000000;
line-height:30px;
background-color:#ffffff;
}
.top_space{
display:block;
margin-top:20px;
}
.font_red{
color:#fd5b78;
}
.ajax_hide{
height:0;
width:0;
position:absolute;
top:0;
left:0;
overflow:hidden;
}
.banner_wrap{
position:fixed;
font-size:0;
bottom:0;
left:0;
width:100%;
}
.banner_wrap img{
width:100%;
}