vue跑马灯效果

28 篇文章 0 订阅

如下图片,会自行向 上“滚动”

 

<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <title>跑马灯 </title>
    <script src="https://cdn.bootcss.com/vue/2.5.17-beta.0/vue.min.js"></script>
    <style>
        div, ul, li, img {
            margin: 0;
            padding: 0;
            box-sizing: border-box;
            display: flex;
        }

        .horseLamp {
            width: 100%;
            height: 50px;
            align-items: center;
            background-color: #ddd;
            display: flex;
            box-sizing: border-box;
        }
        .horseLamp_box {
            display: block;
            position: relative;
            width: 60%;
            height: 30px;
            overflow: hidden;
        }

        .horseLamp_list {
            display: block;
            position: absolute;
            top: 0;
            left: 0;
        }

        .horseLamp_top {
            transition: all 0.2s;
            margin-top: -30px
        }

        .horseLamp_list li {
            height: 30px;
            line-height: 30px;
            font-size: 14px;
        }

    </style>

</head>
<body>

<div class="vueBox">
    <div class="horseLamp">
        <div class="horseLamp_box">
            <ul class="horseLamp_list" :class="{horseLamp_top:animate}">
                <li v-for="(item, index) in horseLampList">
                  <img :src="item.img">
                </li>
            </ul>
        </div>
    </div>
</div>

<script type="text/javascript">
    const vm = new Vue ({
        el: ".vueBox",
        data: {
            animate: false,
            horseLampList: [
                {
                    img:'../assets/logo.png'
                },
                {
                    img:'../assets/logo.png'
                },
                {
                    img:'../assets/logo.png'
                },
                {
                    img:'../assets/logo.png'
                }
            ]
        },
        created: function () {
            setInterval (this.showhorseLamp, 600)
        },
        methods: {
            showhorseLamp: function () {
                this.animate = true;
                setTimeout (() => {
                    this.horseLampList.push (this.horseLampList[ 0 ]);
                    this.horseLampList.shift ();
                    this.animate = false;
                }, 2000);
            }
        }
    });
</script>


</body>
</html>

 

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值