• 12.16VUE小作业


    根据按钮颜色改变正方形颜色

    <!DOCTYPE html>
    <html lang="en">
    <head>
        <meta charset="UTF-8">
        <title>Title</title>
        <style>
            .d1 {
                 200px;
                height: 200px;
    
            }
        </style>
    </head>
    <body>
    <div id="change_color">
            <button @click="f1">蓝色</button>
            <button @click="f2">红色</button>
            <button @click="f3">绿色</button>
        <div class="d1" :style="{backgroundColor:bgc}"></div>
    </div>
    </body>
    <script src="js/vue.js"></script>
    <script>
        new Vue({
            el: '#change_color',
            data: {
                bgc:'red'
            },
            methods: {
                f1(){
                    console.log(this);
                    this.bgc='blue'
                },
                f2(){
                    this.bgc='red'
                },
                f3(){
                    this.bgc='green'
                }
            }
        })
    
    </script>
    </html>
    

    点击变色

    <!DOCTYPE html>
    <html lang="en">
    <head>
        <meta charset="UTF-8">
        <title>Title</title>
        <style>
            .wrap {
                 200px;
                height: 200px;
                background-color: red;
            }
        </style>
    </head>
    <body>
    <div id="app">
        <div class="wrap" :style="{backgroundColor: color}" @click="changeColor"></div>
    </div>
    </body>
    <script src="js/vue.js"></script>
    <script>
        new Vue({
            el: '#app',
            data: {
                color: 'black',
                count: 0,
                colorArr: ['cyan', 'pink', 'green'] // 保存颜色的映射关系
            },
            methods: {
                changeColor() {
                    let n = this.count++;
                    this.color = this.colorArr[n % this.colorArr.length];
                }
            }
        })
    </script>
    </html>
    

    自动旋转变色

    <!DOCTYPE html>
    <html lang="en">
    <head>
        <meta charset="UTF-8">
        <title>Title</title>
        <style>
            .box {
                 200px;
                height: 200px;
                border: 1px solid black;
                border-radius: 50%;
                overflow: hidden;
                position: relative;
            }
    
            .b1 {
                background-color: red;
                position: absolute;
            }
    
            .b2 {
                background-color: green;
                position: absolute;
            }
    
            .left {
                 100px;
                height: 200px;
                left: 0;
            }
    
            .right {
                 100px;
                height: 200px;
                right: 0;
            }
    
            .top {
                 200px;
                height: 100px;
                top: 0;
            }
    
            .buttom {
                 200px;
                height: 100px;
                bottom: 0;
            }
        </style>
    </head>
    <body>
    <div id="app">
        <div class="box" @click="roll">
            <div class="b1" :class="c1"></div>
            <div class="b2" :class="c2"></div>
        </div>
    </div>
    </body>
    <script src="js/vue.js"></script>
    <script>
        let app = new Vue({
            el: '#app',
            data: {
                count: 1,
                c1: 'l',
                c2: 'r',
                c1Arr: ['left', 'top', 'right', 'buttom'],
                c2Arr: ['right', 'buttom', 'left', 'top']
            },
            methods: {
                roll() {
                    let n = this.count++;
                    this.c1 = this.c1Arr[n % 4];
                    this.c2 = this.c2Arr[n % 4];
                }
            }
        });
        // 利用定时器自动旋转图像
        setInterval(function () {
            app.roll();
        }, 500)
    </script>
    </html>
    
  • 相关阅读:
    cmake 学习记录
    OCRTesseract
    IEquatable<T>、IEnumerable<T>
    基于jackson 注解 入参 枚举 反序列化 实操
    基于jackson 将一个String 类型的Json字符串对外输出成 json 格式。
    mysql 中sql 语句查询今天、昨天、7天、近30天、本月、上一月 数据
    mysql 计算两个日期的天数
    iis上json解析失败404
    mybatis foreach split
    mybatis中大于等于小于等于的写法
  • 原文地址:https://www.cnblogs.com/maqiaobin/p/12051087.html
Copyright © 2020-2023  润新知