欧美bbbwbbbw肥妇,免费乱码人妻系列日韩,一级黄片

Vue 實(shí)現(xiàn)簡易多行滾動"彈幕"效果

 更新時間:2020年01月02日 08:43:46   作者:noxxxx  
這篇文章主要介紹了Vue 實(shí)現(xiàn)簡易多行滾動“彈幕”效果,本文通過實(shí)例代碼給大家介紹的非常詳細(xì),具有一定的參考借鑒價值,需要的朋友可以參考下

看一下效果:

 

實(shí)現(xiàn)任意行數(shù)的定時翻滾效果,不使用重復(fù)標(biāo)簽的方式,而是根據(jù)展示個數(shù)判斷是否缺省,并添加對應(yīng)展示個數(shù)的重復(fù)項(xiàng)來實(shí)現(xiàn)。

Vue 的演示代碼如下:

<template>
 <div class="demo-comment-container">
 <div
  class="scroll-container"
  :style="{height: `${height/100}rem`}"
 >
  <ul
  class="scroll-ul"
  :style="{transform: `translate3d(0, ${y/100}rem, 0)`, transition: `${transition}`}"
  >
  <div
   v-for="(item, index) in list"
   :key="index"
   v-bind="baseStyle.style"
   :bgColor="baseStyle.style.bgColor__bg"
   :style="{ color: rgba(baseStyle.color__nf) }"
   :class="['c-item-bg', 'c-item', !item.content && 'empty']"
  >
   <li
   class="c-item"
   >
   <div class="avatar">
    <img
    v-if="item.content"
    class="avatar-item"
    :src="item.photo"
    >
   </div>
   <div
    v-if="item.content"
    class="c-content"
    v-html="item.content"
   />
   </li>
  </div>
  </ul>
 </div>
 <div class="comment-entry">
  <div class="f">
  <div class="text-c">
   <span
   v-if="entry.type === 1"
   class="text"
   v-text="entry.text"
   />
   <div
   v-else
   class="img-container"
   >
   <img :src="entry.image">
   </div>
   <i
   v-if="count"
   class="c-c"
   >{{ count }}</i>
  </div>
  <div>
   <span class="fake-input">來發(fā)表你的看法吧~</span>
  </div>
  </div>
 </div>
 </div>
</template>
<script>
export default {
 inject: ['rgba'],
 props: {
 urlConfig: {
  type: Object,
  default: function () {
  return {}
  }
 },
 type: {
  type: String,
  default: 'hot'
 },
 pageSize: {
  type: Number,
  default: 50
 },
 open: {
  type: Boolean,
  default: true
 },
 entry: {
  type: Object,
  default: function () {
  return {
   type: 1, // 1 文字 2 自定義
   text: '',
   image: ''
  }
  }
 },
 number: {
  type: Number,
  default: 2
 },
 },
 data () {
 return {
  count: 2334,
  dom: null,
  height: 0, // 單項(xiàng)高度
  y: 0, // 每次移動距離
  list: [], // 接口列表
  originLength: 0, // 原始數(shù)組長度
  transition: 'ease all .4s',
  round: 0 // 需要滾動多少輪
 }
 },
 created () {
 this.getCommentList()
 },
 mounted () {
 this.dom = document.querySelector('.c-item')
 // 計算可視區(qū)域高度
 this.height = 64 * this.number + (12 * (this.number - 1))
 },
 methods: {
 getCommentList () {
  // 接口數(shù)據(jù)
  const _list = []
  this.originLength = _list.length
  const mod = this.originLength % this.number
  let need = this.originLength < this.number ? (this.number - this.originLength) : mod > 0 ? this.number - mod : 0 // 計算出要添加的空白元素個數(shù)
  this.list = _list

  // set empty item
  const empty = JSON.parse(JSON.stringify(_list[0]))
  empty.content = ''

  // 補(bǔ)齊空白元素
  while (need) {
  this.list.push(empty)
  need--
  }

  // 填充重復(fù)元素
  let repeat = this.number
  let index = 0
  while (repeat) {
  this.list.push(_list[index])
  index++
  repeat--
  }

  this.round = this.list.length / this.number

  this.scroll()
 },
 scroll () {
  let count = 1
  setInterval(() => {
  count++
  this.y -= this.height + 12 // 移動可視區(qū)域高度 + 最后一個 item 的 margin-bottom
  this.transition = '.4s ease all'
  setTimeout(() => {
   if (count === this.round) {
   count = 1
   this.transition = ''
   this.y = 0
   }
  }, 800)
  }, 2000)
 }
 }
}
</script>

總結(jié)

以上所述是小編給大家介紹的Vue 實(shí)現(xiàn)簡易多行滾動"彈幕",希望對大家有所幫助,如果大家有任何疑問請給我留言,小編會及時回復(fù)大家的。在此也非常感謝大家對腳本之家網(wǎng)站的支持!
如果你覺得本文對你有幫助,歡迎轉(zhuǎn)載,煩請注明出處,謝謝!

相關(guān)文章

  • vue移動端實(shí)現(xiàn)左滑編輯與刪除的全過程

    vue移動端實(shí)現(xiàn)左滑編輯與刪除的全過程

    vue.js是現(xiàn)在流行的js框架之一,vue 是一套用于構(gòu)建用戶界面的漸進(jìn)式j(luò)avascript框架,這篇文章主要給大家介紹了關(guān)于vue移動端實(shí)現(xiàn)左滑編輯與刪除的相關(guān)資料,需要的朋友可以參考下
    2021-05-05
  • vue處理emoji表情占位符的操作方法

    vue處理emoji表情占位符的操作方法

    在計算字符數(shù)時,一般情況下,英文字符、數(shù)字和大部分符號都可以被視為占一個字符長度,因?yàn)樗鼈兪菃蝹€字節(jié),然而,對于某些特殊字符,如表情符號和部分非英文字符,會被認(rèn)為占據(jù)了多個字符長度,本文給介紹了vue處理emoji表情占位符的操作方法,需要的朋友可以參考下
    2024-06-06
  • vue項(xiàng)目中如何引入cesium

    vue項(xiàng)目中如何引入cesium

    這篇文章主要介紹了vue項(xiàng)目中如何引入cesium問題,具有很好的參考價值,希望對大家有所幫助。如有錯誤或未考慮完全的地方,望不吝賜教
    2023-04-04
  • Vue+Vux項(xiàng)目實(shí)踐完整代碼

    Vue+Vux項(xiàng)目實(shí)踐完整代碼

    本文給大家分享一段詳細(xì)的代碼給大家介紹Vue+Vux項(xiàng)目實(shí)踐思路,需要的朋友可以參考下
    2017-11-11
  • vue3 父子組件傳值詳解

    vue3 父子組件傳值詳解

    這篇文章主要為大家介紹了vue的父子組件傳值,具有一定的參考價值,感興趣的小伙伴們可以參考一下,希望能夠給你帶來幫助
    2021-11-11
  • vue項(xiàng)目中使用骨架屏的方法

    vue項(xiàng)目中使用骨架屏的方法

    在頁面加載數(shù)據(jù)之前,有一段空白時間,要么用loading加載,要么就用骨架屏,本文主要介紹了vue項(xiàng)目中使用骨架屏的方法,感興趣的可以了解一下
    2021-05-05
  • vue中動態(tài)添加class類名的方法

    vue中動態(tài)添加class類名的方法

    今天小編就為大家分享一篇vue中動態(tài)添加class類名的方法,具有很好的參考價值,希望對大家有所幫助。一起跟隨小編過來看看吧
    2018-09-09
  • Vue之Computed依賴收集與更新原理分析

    Vue之Computed依賴收集與更新原理分析

    這篇文章主要介紹了Vue之Computed依賴收集與更新原理分析,具有很好的參考價值,希望對大家有所幫助,如有錯誤或未考慮完全的地方,望不吝賜教
    2023-11-11
  • Vue+Vite項(xiàng)目初建(axios+Unocss+iconify)的實(shí)現(xiàn)

    Vue+Vite項(xiàng)目初建(axios+Unocss+iconify)的實(shí)現(xiàn)

    一個好的項(xiàng)目開始搭建總是需要配置許多初始化配置,本文就來介紹一下Vue+Vite項(xiàng)目初建(axios+Unocss+iconify)的實(shí)現(xiàn),具有一定的參考價值,感興趣的可以了解一下
    2024-02-02
  • 淺析Proxy可以優(yōu)化vue的數(shù)據(jù)監(jiān)聽機(jī)制問題及實(shí)現(xiàn)思路

    淺析Proxy可以優(yōu)化vue的數(shù)據(jù)監(jiān)聽機(jī)制問題及實(shí)現(xiàn)思路

    這篇文章主要介紹了淺析Proxy可以優(yōu)化vue的數(shù)據(jù)監(jiān)聽機(jī)制問題及實(shí)現(xiàn)思路,需要的朋友可以參考下
    2018-11-11

最新評論