畫個等分圓玩玩

代碼走起

<!DOCTYPE html>
<html>
<head>
    <meta charset="utf-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <title>test</title>
    <link rel="stylesheet" href="">
    <style>

        #app{
            width: 500px;
            height: 500px;
            margin: 1em auto;
        }

        .container{
            position: relative;
            width: 100%;
            height: 100%;
            overflow: hidden;
            border-radius: 50%;
            z-index: 0;
        }

        .circle{
             position: absolute;
             border-radius: 50%;
        }

        .one{
            width: 98%;
            height: 98%;
            background: #eee;
            z-index: 1;
            top:1%;
            left: 1%;
        }

        .two{
            width: 70%;
            height: 70%;
            z-index: 2;
            left: 15%;
            top: 15%;
            background: #ddd;
        }

        .three{
            width: 40%;
            height: 40%;
            z-index: 3;
            left: 30%;
            top: 30%;
            background: #ccc;
        }

         .thour{
            width: 10%;
            height: 10%;
            z-index: 4;
            left: 45%;
            top: 45%;
            background: #fff;
        }

        .position-box{
            position: relative;
            width: 100%;
            height: 100%;
            overflow: hidden;
            border-radius: 50%;
            color: #FFFFFF;
        }

        .position-box .two-item{
            position: absolute;
            transform-origin: 50% 100%;
            width: 100%;
            height: 50%;
        }
        .position-box .two-item span{
            display: inline-block;
            width: 40%;
            margin: 20% auto;
            text-align: center;
        }

        .position-box .other-item{
            position: absolute;
            transform-origin: left top;
            width: 50%;
            height: 50%;
            left: 50%;
            top: 50%;
            
        }
        .position-box .other-item span{
            display: inline-block;
            overflow: hidden;
            text-align: center;
            width: 50%;
            margin: 45% auto;
        }

        .rotate{
            transform:rotate(720deg) ;
            -ms-transform:rotate(720deg);   /* IE 9 */
            -moz-transform:rotate(720deg);  /* Firefox */
            -webkit-transform:rotate(720deg); /* Safari 和 Chrome */
            -o-transform:rotate(720deg);
            -webkit-transition-duration: 3s;
        }
        .btn-box{

        }

        .btn{
            float: left;
            padding: 5px 10px;
            color: #fff;
            background: green;
            margin-left: 10%;
        }

        .arrowhead-box{
            position: absolute;
            width: 10%;
            height: 10%;
            left: 45%;
            top: 45%;
            z-index: 99;
        }
        .arrowhead{
            height: 3px;
            width: 400%;
            background: #fff;
            margin-top: 50%;
            margin-left: 50%;
        }

    </style>
</head>
<body>
    <div id="app">
        
        <div class="container">
            <div class="circle one">
                <div class="position-box" v-bind:style="{transform:'rotate('+circles.circle1.initAngle+'deg)', '-webkit-transition-duration': times}">
                    <div v-for="(item, index) in circles.circle1.list" class="other-item"
                         v-bind:style="{background: item.bgColor, transform: 'rotate('+circles.circle1.avgAngle*(index)+'deg)skewX(45deg)' }">
                         <span  v-bind:style="{transform: 'rotate('+(circles.circle1.avgAngle*index)*-1+'deg)skewX(1deg)' }" >{{item.content}}</span>
                     </div>
                </div>
            </div>
            <div class="circle two">
                <div class="position-box" v-bind:style="{transform:'rotate('+circles.circle2.initAngle+'deg)', '-webkit-transition-duration': times}">
                    <div v-for="(item, index) in circles.circle2.list" class="two-item"
                         v-bind:style="{background: item.bgColor, transform: 'rotate('+circles.circle2.avgAngle*(index)+'deg)' }">
                            <span>{{item.content}}</span>
                     </div>
                </div>
            </div>
            <div class="circle three">
                <div class="position-box" v-bind:style="{transform:'rotate('+circles.circle3.initAngle+'deg)', '-webkit-transition-duration': times}">
                    <div v-for="(item, index) in circles.circle3.list" class="other-item"
                         v-bind:style="{background: item.bgColor, transform: 'rotate('+circles.circle3.avgAngle*(index)+'deg)skewX(30deg)' }">
                         <span v-bind:style="{transform: 'rotate('+(circles.circle3.avgAngle*index)*-1+'deg)skewX(-30deg)' }" >{{item.content}}</span>
                     </div>
                </div>
            </div>

            <div class="circle thour">
                <div class="position-box" v-bind:style="{transform:'rotate('+circles.circle4.initAngle+'deg)', '-webkit-transition-duration': times}" >
                    <div v-for="(item, index) in circles.circle4.list" class="two-item"
                         v-bind:style="{background: item.bgColor, transform: 'rotate('+circles.circle4.avgAngle*(index)+'deg)' }">
                            <span>{{item.content}}</span>
                     </div>
                </div>
            </div>

            <div class="arrowhead-box">
                <div class="arrowhead"></div>
            </div>

        </div>

        <div class="btn-box">
            <div class="btn" v-on:click="rotateAll">旋轉(zhuǎn)所有</div>
            <!-- <div class="btn" v-on:click="rotateFun4">旋轉(zhuǎn)4</div>
            <div class="btn" v-on:click="rotateFun3">旋轉(zhuǎn)3</div>
            <div class="btn" v-on:click="rotateFun2">旋轉(zhuǎn)2</div>
            <div class="btn" v-on:click="rotateFun1">旋轉(zhuǎn)1</div> -->
        </div>
        <div style="clear: both;margin-top: 10px;" v-html="result">
        </div>

</div>  

   

    <script src="https://cdn.jsdelivr.net/npm/vue@2.6.0"></script>
    <script type="text/javascript">
        var app = new Vue({
          el: '#app',
          data: {
            circles:{
                circle1:{
                    number: 8,
                    initAngle: 0,
                    avgAngle: 45,
                    list:[{
                            content: "喜",
                            bgColor: '#FF99CC'
                        },{
                            content: "怒",
                            bgColor: '#FFCCCC'
                        },{
                            content: "憂",
                            bgColor: '#FFFF99'
                        },{
                            content: "思",
                            bgColor: '#CCCCFF'
                        },{
                            content: "悲",
                            bgColor: '#FF9966'
                        },{
                            content: "恐",
                            bgColor: '#FFCC99'
                        },{
                            content: "驚",
                            bgColor: '#CCFF99'
                        },{
                            content: "全",
                            bgColor: '#CCCCCC'
                        }]
                    },
                    circle2:{
                        number: 2,
                        initAngle: 0,
                        avgAngle: 180,
                        list:[{
                                content: "財富",
                                bgColor: '#333399'
                            },{
                                content: "愛情",
                                bgColor: '#F00000'
                            }]
                    },
                    circle3:{
                        number: 6,
                        initAngle: 0,
                        avgAngle: 60,
                        list:[{
                                content: "責(zé)任",
                                bgColor: '#666699'
                            },{
                                content: "誠信",
                                bgColor: '#FFCCCC'
                            },{
                                content: "尊重",
                                bgColor: '#666699'
                            },{
                                content: "合作",
                                bgColor: '#FFCCCC'
                            },{
                                content: "激情",
                                bgColor: '#666699'
                            },{
                                content: "敬業(yè)",
                                bgColor: '#FFCCCC'
                            }]
                    },
                    circle4:{
                        number: 2,
                        initAngle: 0,
                        avgAngle: 180,
                        list:[{
                                content: "單",
                                bgColor: '#003399'
                            },{
                                content: "雙",
                                bgColor: '#F00000'
                            }]
                    }

            },
            times:'1.5s',
            count: 0,
            result: ""
          },
          computed: {
           
          },
          methods:{
            rotateFun4: function(){
                this.circles.circle4.initAngle= this.circles.circle4.initAngle+this.randomNum();
            },
             rotateFun3: function(){
                this.circles.circle3.initAngle= this.circles.circle3.initAngle+this.randomNum();
            },
             rotateFun2: function(){
                this.circles.circle2.initAngle= this.circles.circle2.initAngle+this.randomNum();
            },
             rotateFun1: function(){
                this.circles.circle1.initAngle= this.circles.circle1.initAngle+this.randomNum();
            },
             rotateAll: function(){
                this.count++;
               this.rotateFun4();
               this.rotateFun3();
               this.rotateFun2();
               this.rotateFun1();
               setTimeout(showResult, 1500);
            },
             randomNum:function(){
                return 720+Math.ceil(Math.random()*360);
            },
            //最終旋轉(zhuǎn)的角度
            resultAngle:function(number){
                if(number == 1){
                    // var rsltAng = this.circles.circle1.initAngle-720*this.count;
                    var rsltAng = this.circles.circle1.initAngle;
                    var angle = Math.ceil(rsltAng/this.circles.circle1.avgAngle);
                    angle = angle%this.circles.circle1.list.length;
                    angle=this.circles.circle1.list.length-angle;
                    if(angle == this.circles.circle1.list.length){
                        angle=0;
                    }
                    console.log("reWard1=",this.circles.circle1.list[angle].content);
                    return this.circles.circle1.list[angle].content;
                }else if(number == 2){
                    var rsltAng = this.circles.circle2.initAngle;
                    var angle = Math.ceil(rsltAng/this.circles.circle2.avgAngle);
                    angle = angle%this.circles.circle2.list.length;
                    if(angle == 0){
                        angle=this.circles.circle2.list.length-1;
                    }else{
                        angle=0;
                    }
                    console.log("reWard2=",this.circles.circle2.list[angle].content);
                    return this.circles.circle2.list[angle].content;
                }else if(number == 3){
                    // var rsltAng = this.circles.circle1.initAngle-720*this.count;
                    var rsltAng = this.circles.circle3.initAngle;
                    var angle = Math.ceil(rsltAng/this.circles.circle3.avgAngle);
                    angle = angle%this.circles.circle3.list.length;
                    angle=this.circles.circle3.list.length-angle;
                    if(angle == this.circles.circle3.list.length){
                        angle=0;
                    }
                    console.log("reWard3=",this.circles.circle3.list[angle].content);
                    return this.circles.circle3.list[angle].content;
                }else if(number == 4){
                    var rsltAng = this.circles.circle4.initAngle;
                    var angle = Math.ceil(rsltAng/this.circles.circle4.avgAngle);
                    angle = angle%this.circles.circle4.list.length;
                    if(angle == 0){
                        angle=this.circles.circle4.list.length-1;
                    }else{
                        angle=0;
                    }
                    console.log("reWard4=",this.circles.circle2.list[angle].content);
                    return this.circles.circle4.list[angle].content;
                }
            }

          }
        })

        //顯示結(jié)果
        function showResult(){
           var content1 =app.resultAngle(1);
           var content2 =app.resultAngle(2);
           var content3 =app.resultAngle(3);
           var content4 =app.resultAngle(4);
           app.result=` <p>今日幸運數(shù)字: ${content4} 數(shù),</p> <p> 工作態(tài)度: ${content3} ,</p> <p>事業(yè)愛情: ${content2},</p> <p>最多心情:${content1}</p>`;
        }
</script>
</body>
</html>
最后編輯于
?著作權(quán)歸作者所有,轉(zhuǎn)載或內(nèi)容合作請聯(lián)系作者
  • 序言:七十年代末夸楣,一起剝皮案震驚了整個濱河市邻邮,隨后出現(xiàn)的幾起案子流炕,更是在濱河造成了極大的恐慌拔稳,老刑警劉巖,帶你破解...
    沈念sama閱讀 216,402評論 6 499
  • 序言:濱河連續(xù)發(fā)生了三起死亡事件,死亡現(xiàn)場離奇詭異,居然都是意外死亡,警方通過查閱死者的電腦和手機该溯,發(fā)現(xiàn)死者居然都...
    沈念sama閱讀 92,377評論 3 392
  • 文/潘曉璐 我一進店門,熙熙樓的掌柜王于貴愁眉苦臉地迎上來别惦,“玉大人狈茉,你說我怎么就攤上這事〔竭洌” “怎么了论皆?”我有些...
    開封第一講書人閱讀 162,483評論 0 353
  • 文/不壞的土叔 我叫張陵,是天一觀的道長猾漫。 經(jīng)常有香客問我点晴,道長,這世上最難降的妖魔是什么悯周? 我笑而不...
    開封第一講書人閱讀 58,165評論 1 292
  • 正文 為了忘掉前任粒督,我火速辦了婚禮,結(jié)果婚禮上禽翼,老公的妹妹穿的比我還像新娘屠橄。我一直安慰自己,他們只是感情好闰挡,可當(dāng)我...
    茶點故事閱讀 67,176評論 6 388
  • 文/花漫 我一把揭開白布锐墙。 她就那樣靜靜地躺著,像睡著了一般长酗。 火紅的嫁衣襯著肌膚如雪溪北。 梳的紋絲不亂的頭發(fā)上,一...
    開封第一講書人閱讀 51,146評論 1 297
  • 那天,我揣著相機與錄音之拨,去河邊找鬼茉继。 笑死,一個胖子當(dāng)著我的面吹牛蚀乔,可吹牛的內(nèi)容都是我干的烁竭。 我是一名探鬼主播,決...
    沈念sama閱讀 40,032評論 3 417
  • 文/蒼蘭香墨 我猛地睜開眼吉挣,長吁一口氣:“原來是場噩夢啊……” “哼派撕!你這毒婦竟也來了?” 一聲冷哼從身側(cè)響起听想,我...
    開封第一講書人閱讀 38,896評論 0 274
  • 序言:老撾萬榮一對情侶失蹤腥刹,失蹤者是張志新(化名)和其女友劉穎,沒想到半個月后汉买,有當(dāng)?shù)厝嗽跇淞掷锇l(fā)現(xiàn)了一具尸體,經(jīng)...
    沈念sama閱讀 45,311評論 1 310
  • 正文 獨居荒郊野嶺守林人離奇死亡佩脊,尸身上長有42處帶血的膿包…… 初始之章·張勛 以下內(nèi)容為張勛視角 年9月15日...
    茶點故事閱讀 37,536評論 2 332
  • 正文 我和宋清朗相戀三年蛙粘,在試婚紗的時候發(fā)現(xiàn)自己被綠了。 大學(xué)時的朋友給我發(fā)了我未婚夫和他白月光在一起吃飯的照片威彰。...
    茶點故事閱讀 39,696評論 1 348
  • 序言:一個原本活蹦亂跳的男人離奇死亡出牧,死狀恐怖,靈堂內(nèi)的尸體忽然破棺而出歇盼,到底是詐尸還是另有隱情舔痕,我是刑警寧澤,帶...
    沈念sama閱讀 35,413評論 5 343
  • 正文 年R本政府宣布豹缀,位于F島的核電站伯复,受9級特大地震影響,放射性物質(zhì)發(fā)生泄漏邢笙。R本人自食惡果不足惜啸如,卻給世界環(huán)境...
    茶點故事閱讀 41,008評論 3 325
  • 文/蒙蒙 一、第九天 我趴在偏房一處隱蔽的房頂上張望氮惯。 院中可真熱鬧叮雳,春花似錦、人聲如沸妇汗。這莊子的主人今日做“春日...
    開封第一講書人閱讀 31,659評論 0 22
  • 文/蒼蘭香墨 我抬頭看了看天上的太陽杨箭。三九已至寞焙,卻和暖如春,著一層夾襖步出監(jiān)牢的瞬間,已是汗流浹背棺弊。 一陣腳步聲響...
    開封第一講書人閱讀 32,815評論 1 269
  • 我被黑心中介騙來泰國打工晶密, 沒想到剛下飛機就差點兒被人妖公主榨干…… 1. 我叫王不留,地道東北人模她。 一個月前我還...
    沈念sama閱讀 47,698評論 2 368
  • 正文 我出身青樓稻艰,卻偏偏與公主長得像,于是被迫代替她去往敵國和親侈净。 傳聞我的和親對象是個殘疾皇子尊勿,可洞房花燭夜當(dāng)晚...
    茶點故事閱讀 44,592評論 2 353