項(xiàng)目需要恋拷,未搜到類似的react的大轉(zhuǎn)盤(pán)盒揉,所以簡(jiǎn)單寫(xiě)了一個(gè)簡(jiǎn)單功能灯谣。
github項(xiàng)目地址
https://github.com/mazhenxiao/buyizhai.git
布衣齋是一個(gè)共享項(xiàng)目將在項(xiàng)目完成后上線
class RotatePlay extends Component{
state={
startList:[],
rotate:0
}
local={
point:0,
angle:0
}
componentDidMount(){
let {startList} = this.props;
this.setState({startList});
}
//模擬數(shù)據(jù)獲取均澳,具體參見(jiàn)yuanyang項(xiàng)目
Ajax_getcurrent(){
let num = parseInt(Math.random()*8)
let da=[{id:num,txt:`${num}等獎(jiǎng)`}];
return da;
}
async Get_Angle(){
let start = 3600;
let {startList,rotate}=this.state;
let {point,angle}=this.local;
let j = 360/startList.length;
let current = await this.Ajax_getcurrent();
let id=startList.findIndex(d=>d.id==current[0].id) //判斷應(yīng)該轉(zhuǎn)到大角度
let end = -(rotate+point*angle+start+j*id);
this.local = {...this.local,...{point:id,angle:j}};
return end;
}
async Event_Click_Rotate(ev){
let start = await this.Get_Angle();
this.setState({rotate:start})
}
renderli=()=>{
let {startList}=this.state;
let h = 100/startList.length;
let r = 1/startList.length;
return startList.map((el,ind)=>{
return <li style={{transform:`rotate(${ind*r}turn)`}} key={ind}>
<img src="" width="50" height="50" />
<p>{el.txt}</p>
</li>
})
}
render(){
let {rotate}=this.state;
return <div className="m-rotatePlay">
<ul refs="MrotateDom" className="m-rotateDom" style={{transform:`rotate(${rotate}deg)`}}>
{
this.renderli()
}
</ul>
<p className="m-rotatePoint" onClick={this.Event_Click_Rotate.bind(this)}>抽獎(jiǎng)</p>
</div>
}
}
export default RotatePlay;
- less代碼,頁(yè)面按照1/7.5 布局
@f:100rem;
.m-rotatePlay{
width:400/@f;height:400/@f;position: relative;top:0;left:0; margin:10/@f auto;
.m-rotateDom{
width:100%;height:100%;border:#088 solid 1px;position: relative;top:0;left:0;
transform: rotate(0deg);
border-radius:50%;overflow: hidden;
li{
list-style: none;
position: absolute;;
top:0;left:0;text-align: center;
width:100%;height:100%;
transform-origin:50% 200/@f;
}
transition:transform 6s ease;
}
.m-rotatePoint{
width:100/@f;height:100/@f;position: absolute;top:50%;left:50%;border:#ccc solid 1px;background:rgb(211, 139, 44);
transform:translateX(-50%) translateY(-50%);text-align: center;line-height:100/@f;color:#fff;border-radius:50%;cursor: pointer;
&:before{
content:"";position: absolute;top:0;left:50%;width:20/@f;height:40/@f;background: burlywood;transform:translateX(-50%) translateY(-100%);
clip-path: polygon(11px 0px, 0px 41px, 21px 41px);border:#ccc solid 1px;
}
}
}