拍行榜,排名无限滚动,css实现

废话不多说,直接上代码

<!DOCTYPE html>
<html>

<head>
    <meta charset="utf-8">
    <title></title>
    <script src="https://unpkg.com/vue@2.6.14/dist/vue.min.js"></script>
    <style>
        .box div {
            width: 300px;
            padding: 1rem 0;
            background-color: aquamarine;
        }
    </style>
</head>

<body>
    <div id="app">
        <div style="height: 200px;overflow: hidden;">
            <div class="box"
                :style="{ transitionDuration: `${transitionDuration}ms`, transform: `translateY( ${translateX}px)`}">
                <div class="scroll_box" v-for="(item,index) in list" :key="item.name">{{item.name}}</div>
            </div>
            <div class="box" v-if="list.length>4"
                :style=" { transitionDuration: `${transitionDuration}ms`, transform: `translateY( ${translateX}px)`}">
                <div class="scroll_box" v-for="(item,index) in list" :key="item.name">{{item.name}}</div>
            </div>

        </div>
    </div>
</body>
<script>
    new Vue({
        el: '#app',
        data: {
            translateX: 0,
            transitionDuration: 500,
            translateValue: 200,
            switeCount: 4,
            maxRow: 4,
            time: '',
            list: [{
                name: 1,
            }, {
                name: 2,
            }, {
                name: 3,
            }, {
                name: 4,
            }, {
                name: 5,
            },]
        },
        mounted() {
            if (this.list.length > 4) {
                this.scroll()
            }
        },
        methods: {
            scroll() {
                this.translateValue = document.querySelectorAll('.scroll_box')[0].clientHeight
                this.switeCount = document.querySelectorAll('.scroll_box').length / 2
                console.log(this.translateValue, 'this.translateValue');
                console.log(this.switeCount, 'this.switeCount');
                console.log(-this.translateValue * this.switeCount - 4 * this.translateValue, 'this.translateValue * this.switeCount');
                this.time = setInterval(() => {
                    this.translateX -= this.translateValue
                    console.log(this.translateX, 'this.translateX');
                    this.transitionDuration = 500
                    if (this.translateX === (-this.translateValue * this.switeCount)) {
                        setTimeout(() => {
                            this.translateX -= this.translateValue
                            this.transitionDuration = 0
                            this.translateX = 0
                        }, 400)
                        console.log(1111);

                    }
                }, 2000)
            },
        },
        beforeDestroy() {
            clearInterval(this.time)
        },
    })
</script>

</html>

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值