画个等分圆玩玩

代码走起

<!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">旋转所有</div>
            <!-- <div class="btn" v-on:click="rotateFun4">旋转4</div>
            <div class="btn" v-on:click="rotateFun3">旋转3</div>
            <div class="btn" v-on:click="rotateFun2">旋转2</div>
            <div class="btn" v-on:click="rotateFun1">旋转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: "责任",
                                bgColor: '#666699'
                            },{
                                content: "诚信",
                                bgColor: '#FFCCCC'
                            },{
                                content: "尊重",
                                bgColor: '#666699'
                            },{
                                content: "合作",
                                bgColor: '#FFCCCC'
                            },{
                                content: "激情",
                                bgColor: '#666699'
                            },{
                                content: "敬业",
                                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);
            },
            //最终旋转的角度
            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;
                }
            }

          }
        })

        //显示结果
        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>今日幸运数字: ${content4} 数,</p> <p> 工作态度: ${content3} ,</p> <p>事业爱情: ${content2},</p> <p>最多心情:${content1}</p>`;
        }
</script>
</body>
</html>
最后编辑于
©著作权归作者所有,转载或内容合作请联系作者
  • 序言:七十年代末,一起剥皮案震惊了整个滨河市,随后出现的几起案子,更是在滨河造成了极大的恐慌,老刑警刘岩,带你破解...
    沈念sama阅读 158,736评论 4 362
  • 序言:滨河连续发生了三起死亡事件,死亡现场离奇诡异,居然都是意外死亡,警方通过查阅死者的电脑和手机,发现死者居然都...
    沈念sama阅读 67,167评论 1 291
  • 文/潘晓璐 我一进店门,熙熙楼的掌柜王于贵愁眉苦脸地迎上来,“玉大人,你说我怎么就摊上这事。” “怎么了?”我有些...
    开封第一讲书人阅读 108,442评论 0 243
  • 文/不坏的土叔 我叫张陵,是天一观的道长。 经常有香客问我,道长,这世上最难降的妖魔是什么? 我笑而不...
    开封第一讲书人阅读 43,902评论 0 204
  • 正文 为了忘掉前任,我火速办了婚礼,结果婚礼上,老公的妹妹穿的比我还像新娘。我一直安慰自己,他们只是感情好,可当我...
    茶点故事阅读 52,302评论 3 287
  • 文/花漫 我一把揭开白布。 她就那样静静地躺着,像睡着了一般。 火红的嫁衣衬着肌肤如雪。 梳的纹丝不乱的头发上,一...
    开封第一讲书人阅读 40,573评论 1 216
  • 那天,我揣着相机与录音,去河边找鬼。 笑死,一个胖子当着我的面吹牛,可吹牛的内容都是我干的。 我是一名探鬼主播,决...
    沈念sama阅读 31,847评论 2 312
  • 文/苍兰香墨 我猛地睁开眼,长吁一口气:“原来是场噩梦啊……” “哼!你这毒妇竟也来了?” 一声冷哼从身侧响起,我...
    开封第一讲书人阅读 30,562评论 0 197
  • 序言:老挝万荣一对情侣失踪,失踪者是张志新(化名)和其女友刘颖,没想到半个月后,有当地人在树林里发现了一具尸体,经...
    沈念sama阅读 34,260评论 1 241
  • 正文 独居荒郊野岭守林人离奇死亡,尸身上长有42处带血的脓包…… 初始之章·张勋 以下内容为张勋视角 年9月15日...
    茶点故事阅读 30,531评论 2 245
  • 正文 我和宋清朗相恋三年,在试婚纱的时候发现自己被绿了。 大学时的朋友给我发了我未婚夫和他白月光在一起吃饭的照片。...
    茶点故事阅读 32,021评论 1 258
  • 序言:一个原本活蹦乱跳的男人离奇死亡,死状恐怖,灵堂内的尸体忽然破棺而出,到底是诈尸还是另有隐情,我是刑警宁泽,带...
    沈念sama阅读 28,367评论 2 253
  • 正文 年R本政府宣布,位于F岛的核电站,受9级特大地震影响,放射性物质发生泄漏。R本人自食恶果不足惜,却给世界环境...
    茶点故事阅读 33,016评论 3 235
  • 文/蒙蒙 一、第九天 我趴在偏房一处隐蔽的房顶上张望。 院中可真热闹,春花似锦、人声如沸。这庄子的主人今日做“春日...
    开封第一讲书人阅读 26,068评论 0 8
  • 文/苍兰香墨 我抬头看了看天上的太阳。三九已至,却和暖如春,着一层夹袄步出监牢的瞬间,已是汗流浃背。 一阵脚步声响...
    开封第一讲书人阅读 26,827评论 0 194
  • 我被黑心中介骗来泰国打工, 没想到刚下飞机就差点儿被人妖公主榨干…… 1. 我叫王不留,地道东北人。 一个月前我还...
    沈念sama阅读 35,610评论 2 274
  • 正文 我出身青楼,却偏偏与公主长得像,于是被迫代替她去往敌国和亲。 传闻我的和亲对象是个残疾皇子,可洞房花烛夜当晚...
    茶点故事阅读 35,514评论 2 269