vue文字间歇无缝向上滚动

公司的管理系统中有“文字间歇无缝向上滚动”的需求,现在这种需求基本在项目开发中已经消失了,没什么新颖的,但架不住公司高层喜欢这种玩意儿,所以,作为开发人员,即使你有一百个不乐意,谁让是人家给你发工资呢!!!

其实,这种用在vue项目中的需求跟原生js的实现方法基本一致,且实现的方法有多种,今天就单拎出来一种实现方法吧:

<div class="scroll-up" ref="scroll">
      <ul>
        <li v-for="item in scrollData" :key="item.id"><router-link to="">{{item.title}}</router-link></li>
      </ul>
    </div>
export default {
  data() {
    return {
      scrollData: [
        { id: 1, title: '架不住公司高层喜欢这种玩意儿' },
        { id: 2, title: '用在vue项目中的需求跟原生js的实现方法' },
        { id: 3, title: '文字间歇无缝向上滚动' },
        { id: 4, title: '即使你有一百个不乐意,谁让是人家给你发工资呢' },
        { id: 5, title: '今天就单拎出来一种实现方法' },
      ],
      scrollArea: '',
      speed: 20,
      timer: null,
      delay: 3000,
      liHeight: '',
    };
  },
  mounted() {
    this.$nextTick(() => {
      this.scrollArea = this.$refs.scroll;
      let li = this.scrollArea.getElementsByTagName("li");
      this.liHeight = li[0].offsetHeight;
      this.scrollArea.scrollTop = 0;
      this.scrollArea.innerHTML += this.scrollArea.innerHTML;

      setTimeout(this.startScroll, this.delay);
    })
  },
  methods: {
    startScroll(){
      this.timer = setInterval(this.scrollUp, this.speed);
      this.scrollArea.scrollTop++;
    },
    scrollUp(){
      if(this.scrollArea.scrollTop % this.liHeight == 0){
        clearInterval(this.timer);
        setTimeout(this.startScroll, this.delay);
      }else{
        this.scrollArea.scrollTop++;
        if(this.scrollArea.scrollTop >= this.scrollArea.scrollHeight / 2){
          this.scrollArea.scrollTop = 0;
        }
      }
    },
  }
}
<style scoped>
.scroll-up{height:50px;line-height:50px;overflow:hidden;}
</style>

就酱!

原文地址:https://www.cnblogs.com/tnnyang/p/11613654.html

时间: 2024-08-07 01:51:42

vue文字间歇无缝向上滚动的相关文章

文字列表无缝向上滚动JavaScript代码

<!DOCTYPE html> <html> <head> <meta charset=utf-8> <title>文字列表无缝向上滚动JavaScript代码-代码库</title> <style> *{margin:0px;padding:0px;border:0px;} body{font-size:12px} a{color:#333333; text-decoration:none;} a:hover{color

jquery插件之文字间歇自动向上滚动

该插件乃本博客作者所写,目的在于提升作者的js能力,也给一些js菜鸟在使用插件时提供一些便利,老鸟就悠然地飞过吧. 此插件旨在实现目前较为流行的文字间歇向上滚动特效,当鼠标移动到文字上时,向上滚动会停止,当鼠标离开时,向上滚动继续.整体代码如下: <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transition

jquery插件之文字无缝向上滚动

该插件乃本博客作者所写,目的在于提升作者的js能力,也给一些js菜鸟在使用插件时提供一些便利,老鸟就悠然地飞过吧. 此插件旨在实现目前较为流行的无缝向上滚动特效,当鼠标移动到文字上时,向上滚动会停止,当鼠标离开时,向上滚动继续.整体代码如下: <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional

基于zepto的插件之移动端无缝向上滚动并上下触摸滑动

该插件乃本博客作者所写,目的在于提升作者的js能力,也给一些js菜鸟在使用插件时提供一些便利,老鸟就悠然地飞过吧. 公司的移动端项目是基于zepto的,有一个页面要求文字能够无缝地不停向上滚动,但查了网上的资料,大多都是基于jquery的,虽然稍作修改就可以用于移动端,但不能实现触摸上下翻滚.所以就去了zepto的官网查看其API,却发现如果要使用zepto的swipe()方法,需要引用其已经封装好的touch.js文件,我就赶紧引用了这个js文件,可在实际测试中,官网给出的touch.js文件

简单的jQuery无缝向上滚动效果

html <!DOCTYPE html><html lang="zh-CN"><head><meta charset="utf-8"><title>简单的jQuery无缝向上滚动效果演示1_dowebok</title><style>* { margin: 0; padding: 0;}.myscroll { width: 300px; height: 260px; margin:

js制作无缝向上滚动的广告

---------------------------------------------------------------------------------------------------------------css @charset "gb2312";/* CSS Document */ body{ margin:0; margin-top:3px; padding:0; font-size:12px; line-height:20px; color:#333;}.dom

[javascript]文字无缝向上滚动

静态代码: <div style="height:30px;overflow:hidden;"> <div id='marquee'> <p>第1段</p> <p>第2段</p> <p>第3段</p> <p>第4段</p> <p>第5段</p> </div> </div> 解释:首先最外层是一个高度只有30px的层,这样

无缝向上滚动原理代码

<script> $(document).ready(function () { var ll = 0;//向上移动的距离 var rolling = setInterval(function () { star() }, 1000); var leng = $('.rolling').children().length;//获取滚动的个数 var hei = leng * 30 + 30;//30是滚动的距离 $(".rolling-li:last-child").aft

jquery无缝向上滚动实现代

<!DOCTYPE html><html><head><style type="text/css">.renav{width:200px;height:150px;overflow:hidden;}.renav li{height:21px;border-bottom:solid 1px blue;list-style-type:none;}</style><body><div class="ren