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

vue列表自動滾動實例

 更新時間:2023年10月09日 08:48:13   作者:學不會190  
這篇文章主要介紹了vue列表自動滾動實例代碼,具有很好的參考價值,希望對大家有所幫助,如有錯誤或未考慮完全的地方,望不吝賜教

vue列表自動滾動

想要實現(xiàn)vue列表數(shù)據(jù)自動滾動,鼠標劃入列表滾動停止

就是這樣的效果

下面上代碼

首先安裝 npm install vue-seamless-scroll --save

npm install vue-seamless-scroll --save

在需要的頁面引入

import vueSeamlessScroll from "vue-seamless-scroll";

使用

<vueSeamlessScroll
   :data="vehicleRecordListData"
   class="seamless-warp"
   :class-option="defaultOption"
 >
   <ul class="item">
      <li
           v-for="(item, index) in vehicleRecordListData"
           :key="index"
        >
                        <span class="title" v-text="item.inAutoPlate"></span>
                        <span class="date" v-text="item.vehicleCategory"></span>
                        <span class="date" v-text="item.isInOrOut"></span>
                        <span>{{ item.inOrOutTime | dateFormatValue }}</span>
                        <span>{{ item.inOrOutType }}</span>
                        <span>{{ item.inOrOutLaneName }}</span>
                      </li>
                    </ul>
                  </vueSeamlessScroll>

配置項

keydescriptiondefaultval
step數(shù)值越大速度滾動越快1Number
limitMoveNum開啟無縫滾動的數(shù)據(jù)量5Number
hoverStop是否啟用鼠標hover控制 true Boolean 
direction方向 0 往下 1 往上 2向左 3向右1Number
openTouch移動端開啟touch滑動 true  Boolean  
singleHeight單步運動停止的高度(默認值0是無縫不停止的滾動) direction => 0/10Number
singleWidth單步運動停止的寬度(默認值0是無縫不停止的滾動) direction => 2/30Number
waitTime單步停止等待時間(默認值1000ms)1000Number

vue列表 自動滾動 加 鼠標滾輪

<template>
  <div class="scroll-container" id="scrollContainer">
    <Scroll :id="'service'">
      <template>
        <!-- <div v-for="(item,idx) in scrollListData" :key="idx + 'n'" class="service" @click="rowClick(item)">
          {{item.name}}
        </div> -->
        <ul>
          <li v-for="(item,idx) in scrollListData" :key="idx + 'n'" class="service" @click="rowClick(item)">
            <div class="service-chaild">{{ item.name }}</div>
            <div class="service-chaild">{{ item.value }}</div>
          </li>
        </ul>
      </template>
    </Scroll>
  </div>
</template>
<script>
  import Scroll from "@/components/HelloWorld";
  export default {
    name: 'TestPage',
    components: {
      Scroll
    },
    data() {
      return {
        scrollListData: [{
            name: '嘉興',
            value: '5555'
          },
          {
            name: '上海',
            value: '5555'
          },
          {
            name: '蘇州',
            value: '5555'
          },
          {
            name: '南京',
            value: '5555'
          },
          {
            name: '嘉興',
            value: '5555'
          },
          {
            name: '上海',
            value: '5555'
          },
          {
            name: '蘇州',
            value: '5555'
          },
          {
            name: '南京',
            value: '5555'
          },
          {
            name: '嘉興',
            value: '5555'
          },
          {
            name: '上海',
            value: '5555'
          },
          {
            name: '蘇州',
            value: '5555'
          },
          {
            name: '南京',
            value: '5555'
          }
        ]
      };
    },
    methods: {
      rowClick(row) {
        console.log(row, 'row ==================')
      }
    },
  };
</script>
<style>
  .scroll-container {
    height: 200px;
    width: 200px;
    margin-bottom: 20px;
  }
  .service {
    font-size: 12px;
    line-height: 18px;
    cursor: pointer;
    display: flex;
  }
  .service:nth-child(odd) {
    background: yellow;
  }
  .service:nth-child(even) {
    background: orange;
  }
  .service-chaild {
    height: 50px;
  }
</style>
<template>
  <div class="scrollContainer" :id="id" @mouseenter="monseenter" @mouseleave="mouseleave">
    <slot></slot>
  </div>
</template>
<script>
  export default {
    name: 'ScrollList',
    props: {
      id: String
    },
    data() {
      return {
        timer: null
      };
    },
    methods: {
      init() {
        this.setTimer();
        // this.$once代表只執(zhí)行一次。如果組件是在keep-alive中包裹,則需要更換函數(shù)
        // 被keep-alive包裹住的組件有兩個生命周期函數(shù):activated和deactivated
        this.$once('hook:beforeDestroy', () => {
          this.removeTimer();
        });
      },
      removeTimer() {
        if (this.timer) {
          clearInterval(this.timer);
          this.timer = null;
        }
      },
      setTimer() {
        this.removeTimer();
        this.timer = setInterval(() => {
          // pixel height:include el and padding    read only
          const scrollHeight = document.getElementById(this.id).scrollHeight;
          // visible area height:include el and padding  read only
          const clientHeight = document.getElementById(this.id).clientHeight;
          const heightDifference = scrollHeight - clientHeight;
          // scroll height:readable and writable
          document.getElementById(this.id).scrollTop++;
          // when el scroll to top
          if (document.getElementById(this.id).scrollTop >= heightDifference - 1) {
            this.removeTimer();
            // make it go back to original location after one second
            setTimeout(() => {
              document.getElementById(this.id).scrollTop = 0;
              this.setTimer();
            }, 1000);
          }
        }, 44);
      },
      monseenter() {
        this.removeTimer();
      },
      mouseleave() {
        this.setTimer();
      }
    },
    mounted() {
      this.init();
    }
  };
</script>
<style>
  .scrollContainer::-webkit-scrollbar {
    width: 4px;
    background: aliceblue;
  }
  .scrollContainer::-webkit-scrollbar-thumb {
    background: palevioletred;
    border-radius: 5px;
  }
  .scrollContainer {
    height: 100%;
    overflow: scroll;
    overflow-x: hidden;
  }
  /* // 兼容IE */
  .scrollContainer {
    /*三角箭頭的顏色*/
    scrollbar-arrow-color: #fff;
    /*滾動條滑塊按鈕的顏色*/
    scrollbar-face-color: #0099dd;
    /*滾動條整體顏色*/
    scrollbar-highlight-color: #0099dd;
    /*滾動條陰影*/
    scrollbar-shadow-color: #0099dd;
    /*滾動條軌道顏色*/
    scrollbar-track-color: #0066ff;
    /*滾動條3d亮色陰影邊框的外觀顏色——左邊和上邊的陰影色*/
    scrollbar-3dlight-color: #0099dd;
    /*滾動條3d暗色陰影邊框的外觀顏色——右邊和下邊的陰影色*/
    scrollbar-darkshadow-color: #0099dd;
    /*滾動條基準顏色*/
    scrollbar-base-color: #0099dd;
  }
</style>

總結(jié)

以上為個人經(jīng)驗,希望能給大家一個參考,也希望大家多多支持腳本之家。

相關(guān)文章

  • vue實現(xiàn)多個元素或多個組件之間動畫效果

    vue實現(xiàn)多個元素或多個組件之間動畫效果

    這篇文章主要為大家詳細介紹了vue實現(xiàn)多個元素或多個組件之間動畫效果,具有一定的參考價值,感興趣的小伙伴們可以參考一下
    2018-09-09
  • Vue安裝sass-loader和node-sass版本匹配的報錯問題

    Vue安裝sass-loader和node-sass版本匹配的報錯問題

    這篇文章主要介紹了Vue安裝sass-loader和node-sass版本匹配的報錯問題,具有很好的參考價值,希望對大家有所幫助,如有錯誤或未考慮完全的地方,望不吝賜教
    2024-04-04
  • 使用Vue3和Plotly.js繪制交互式漏斗圖的示例代碼

    使用Vue3和Plotly.js繪制交互式漏斗圖的示例代碼

    漏斗圖常用于可視化業(yè)務(wù)流程中的各個階段的轉(zhuǎn)換率,例如銷售漏斗或營銷漏斗,它可以幫助用戶識別流程中的瓶頸和改進機會,本文給大家介紹了如何使用Vue3和Plotly.js繪制交互式漏斗圖,,文中有相關(guān)代碼示例供大家參考,需要的朋友可以參考下
    2024-07-07
  • 關(guān)于vue項目部署后刷新網(wǎng)頁報404錯誤解決

    關(guān)于vue項目部署后刷新網(wǎng)頁報404錯誤解決

    這篇文章主要介紹了關(guān)于vue項目部署后刷新網(wǎng)頁報404錯誤解決,具有很好的參考價值,希望對大家有所幫助。如有錯誤或未考慮完全的地方,望不吝賜教
    2022-07-07
  • vue中實現(xiàn)拖拽排序功能的詳細教程

    vue中實現(xiàn)拖拽排序功能的詳細教程

    在業(yè)務(wù)中列表拖拽排序是比較常見的需求,下面這篇文章主要給大家介紹了關(guān)于vue中實現(xiàn)拖拽排序功能的詳細教程,文中通過實例代碼介紹的非常詳細,需要的朋友可以參考下
    2022-08-08
  • Proxy中代理數(shù)據(jù)攔截的方法詳解

    Proxy中代理數(shù)據(jù)攔截的方法詳解

    這篇文章主要為大家詳細介紹了Proxy中代理數(shù)據(jù)攔截的方法,文中的示例代碼講解詳細,對我們學習或工作具有一定的借鑒價值,需要的可以參考一下
    2022-12-12
  • vue-quill-editor插入圖片路徑太長問題解決方法

    vue-quill-editor插入圖片路徑太長問題解決方法

    這篇文章主要介紹了vue-quill-editor插入圖片路徑太長問題解決方法,文中通過示例代碼介紹的非常詳細,對大家的學習或者工作具有一定的參考學習價值,需要的朋友們下面隨著小編來一起學習學習吧
    2021-01-01
  • Vue el-table表頭上引入組件不能實時傳參解決方法分析

    Vue el-table表頭上引入組件不能實時傳參解決方法分析

    這篇文章主要介紹了Vue el-table表頭上引入組件不能實時傳參解決方法,總的來說這并不是一道難題,那為什么要拿出這道題介紹?拿出這道題真正想要傳達的是解題的思路,以及不斷優(yōu)化探尋最優(yōu)解的過程。希望通過這道題能給你帶來一種解題優(yōu)化的思路
    2022-11-11
  • vite項目無法使用zangodb包裝器的解決方案

    vite項目無法使用zangodb包裝器的解決方案

    vite作為新一代工具鏈,具有很多便利之處,配置也非常簡單,它很好地整合了Rollup和其他復(fù)雜的構(gòu)建項,并提供了多種方向的典型腳手架模板,深受大家喜愛,本文給大家介紹了如何解決vite項目無法使用zangodb包裝器的問題,需要的朋友可以參考下
    2023-10-10
  • vue單頁應(yīng)用的內(nèi)存泄露定位和修復(fù)問題小結(jié)

    vue單頁應(yīng)用的內(nèi)存泄露定位和修復(fù)問題小結(jié)

    系統(tǒng)進程不再用到的內(nèi)存,沒有及時釋放,就叫做內(nèi)存泄漏(memory leak)。這篇文章主要介紹了vue單頁應(yīng)用的內(nèi)存泄露定位和修復(fù),需要的朋友可以參考下
    2019-08-08

最新評論