vue marquee原生实现

<template>

<div class="index">

<div class="scroll">

<ul :style="{top}" :class="{transition:index!=0}">

<li v-for="item in list" @click="hh">{{"第"+item+"条数据"}}</li>

<!-- <li>{{"第"+list[0]+"条数据"}}</li> -->

</ul>

</div>

<router-link to="/">hello</router-link>

</div>

</template>

<script>

export default {

name: "HelloWorld",

data() {

return {

list: ["一", "二", "三", "四", "五", "六", "七", "八", "九", "十"],

top: "",

index: 0,

p: ""

};

},

mounted() {

this.goScroll();

},

methods: {

hh() {

alert(1);

},

goScroll() {

var _this = this;

this.p = setInterval(() => {

console.log(22);

_this.top = -60 * _this.index + "px";

if (_this.index >= this.list.length + 1) {

_this.index = 0;

_this.top = -0 + "px";

clearInterval(_this.p);

// _this.continueScroll();

this.goScroll();

} else {

_this.index++;

}

}, 2000);

}

// continueScroll() {

// var _this = this;

// setTimeout(() => {

// _this.index = 1;

// _this.top = -60 * this.index + "px";

// _this.index++;

// this.goScroll();

// }, 100);

// }

},

destroyed() {

clearInterval(this.p);

}

};

</script>

<style>

img {

width: 30px;

height: 30px;

border-radius: 50%;

vertical-align: middle;

margin-right: 20px;

}

ul {

position: relative;

}

li {

overflow: hidden;

white-space: nowrap;

text-overflow: ellipsis;

width: 80%;

height: 60px;

line-height: 60px;

text-align: left;

margin: 0;

font-size: 14px;

/* transform: scale(0.5); */

}

.scroll {

height: 60px;

overflow: hidden;

font-size: 0px;

position: relative;

}

.transition {

transition: top 2s;

}

</style>


 

转载于:https://my.oschina.net/u/4004801/blog/3058497

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

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

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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值