zoukankan      html  css  js  c++  java
  • tab选项卡平滑滚动vue

    <html lang="en">
    <head>
        <meta charset="UTF-8">
        <title>Title</title>
        <script src="https://cdn.jsdelivr.net/npm/vue/dist/vue.js"></script>
        <style>
            ul {
                padding: 0
            }
            ul li {
                list-style: none;
            }
            .tab ul{
                position: relative;
                background: #333;
            }
            .tab ul li {
                display: inline-block;
                padding: 50px;
                 100px;
                height: 25px;
                margin: 0;
                background: #ccc;
                text-align: center;
                border: 1px solid #000;
            }
            .tab .bottom {
                position: absolute;
                left: 0;
                 100px;
                height: 3px;
                background: #f00;
                transition: all .2s;
            }
        </style>
    </head>
    <body>
    <div class="tab" id="box">
        <ul ref ="tabWrapper">
            <li v-for="(item, index) in list" @click="tabClick(index, $event)">{{item}}</li>
            <div class="bottom" :style="style"></div>
        </ul>
    </div>
    </body>
    
    <script>
        new Vue({
            el:'#box',
            data:{
                list: [1,2,3,4,5],
                style: {}
            },
            mounted() {
                this.$nextTick(() => {
                    const firstLi = this.$refs.tabWrapper.querySelector('li:nth-of-type(1)')
                    this.style = {
                        left: firstLi.offsetLeft + 'px',
                         firstLi.offsetWidth +'px'
                    }
                })
            },
            methods:{
                tabClick(index, e) {
                    console.log(e)
                    console.log(e.target.offsetWidth)
                    console.log(e.target.offsetLeft)
                    this.style = {
                        left: e.target.offsetLeft + 'px',
                         e.target.offsetWidth +'px'
                    }
                }
            }      
        });
    </script>
    </html>
  • 相关阅读:
    HDU
    纯C++去雾算法
    拓扑排序
    SG 函数初步 HDU 1536 &amp;&amp; HDU 1944
    <html>
    XML制作RSS源
    ACM退役前2个月总结
    javascript 的 jasmine 的測试语句
    Vue.js父与子组件之间传参
    $.contents().find设置的data在iframe子页面无法获取值
  • 原文地址:https://www.cnblogs.com/hyshi/p/11139521.html
Copyright © 2011-2022 走看看