美文网首页
vue+css动画实现下拉菜单上、下箭头切换

vue+css动画实现下拉菜单上、下箭头切换

作者: 似朝朝我心 | 来源:发表于2022-03-08 21:55 被阅读0次

    单击事件触发型:

    <!DOCTYPE html>
    <html lang="en">
    
    <head>
        <meta charset="UTF-8">
        <meta http-equiv="X-UA-Compatible" content="IE=edge">
        <meta name="viewport" content="width=device-width, initial-scale=1.0">
        <title>Document</title>
        <script src="https://cdn.jsdelivr.net/npm/vue@2/dist/vue.js"></script>
    </head>
    <style>
        .arrowTransform {
            transition: 0.2s;
            transform-origin: center;
            transform: rotateZ(180deg);
        }
    
        .arrowTransformReturn {
            transition: 0.2s;
            transform-origin: center;
            transform: rotateZ(0deg);
        }
    </style>
    
    <body>
        <div id="app"><img :class="{ 'arrowTransform': !flag, 'arrowTransformReturn': flag}" src="1.png" alt=""
                @click="flag = !flag"></div>
        <script>
            const app = new Vue({
                el: "#app",
                data: {
                    flag: false
                }
            })
        </script>
    </body>
    
    </html>
    

    hover型:利用字体图标结合动画

    CSS的rotate只 对block或 inline-block类型元素有效

    <!DOCTYPE html>
    <html lang="en">
    <head>
        <meta charset="UTF-8">
        <meta http-equiv="X-UA-Compatible" content="IE=edge">
        <meta name="viewport" content="width=device-width, initial-scale=1.0">
        <title>Document</title>
        <script src="https://cdn.jsdelivr.net/npm/vue@2/dist/vue.js"></script>
        <link rel="stylesheet" href="http://at.alicdn.com/t/font_3231229_sv4mc3i24fh.css">
    </head>
    <style>
       span {
           display: inline-block;
       }
       .more:hover {
        color: aqua;
       }
       .more:hover .trans{
        transform:rotate(180deg);
        color: aqua;
       }
    </style>
    
    <body>
        <div id="app">
            <div class="more">
                更多<span class="iconfont icon-xiangxiajiantou trans"></span>
            </div>
        </div>
        <script>
            const app = new Vue({
                el: "#app",
                data: {
                }
            })
        </script>
    </body>
    </html>
    

    相关文章

      网友评论

          本文标题:vue+css动画实现下拉菜单上、下箭头切换

          本文链接:https://www.haomeiwen.com/subject/wlhzrrtx.html