vue3鼠標(biāo)拖拽滑動(dòng)效果實(shí)現(xiàn)demo
vue3-dragscroll來(lái)實(shí)現(xiàn)
使用element-plus在頁(yè)面里寫(xiě)一個(gè)表格,表格有橫向和豎向滾動(dòng)條,想實(shí)現(xiàn)表格可以鼠標(biāo)拖拽滾動(dòng)。
可以用vue3-dragscroll來(lái)實(shí)現(xiàn),首先需要在css里隱藏掉表格的滾動(dòng)條,將表格的父級(jí)設(shè)置固定的寬高,并在父級(jí)標(biāo)簽上增加v-dragscroll指令。
<template> <div class="data-table" v-dragscroll> <el-table :data="rowData" border :show-header="false" table-layout="auto" size="small" > <el-table-column :prop="item.prop" v-for="item of columns" :key="item.prop" :fixed="item.fixed ? true : false" :width="item.width" > </el-table-column> </el-table> </div> </template> <script lang="ts" setup> import { ref } from 'vue' import { useDataTable } from './scripts/data-table' const { columns, rowData } = useDataTable() </script> <style scoped lang="scss"> .data-table { width: 630px; height: 320px; overflow: auto; border: solid 1px #ebeef5; &::-webkit-scrollbar { width: 6px; height: 6px; } &::-webkit-scrollbar-track { width: 6px; background: rgba(#101F1C, 0.1); -webkit-border-radius: 2em; -moz-border-radius: 2em; border-radius: 2em; } &::-webkit-scrollbar-thumb { background-color: rgba(144,147,153,.5); background-clip: padding-box; min-height: 6px; -webkit-border-radius: 2em; -moz-border-radius: 2em; border-radius: 2em; transition: background-color .3s; cursor: pointer; } &::-webkit-scrollbar-thumb:hover { background-color: rgba(144,147,153,.3); } } :deep .el-table { width: fit-content; max-width: none; border: none; } :deep .el-scrollbar__bar.is-vertical { width: 0; } :deep .data-table thead { height: 0; display: block; } :deep .hide_line .el-table td.el-table__cell { border-bottom: none; } :deep .data-table .el-table--small .el-table__cell { padding: 0; } :deep .data-table .el-table--small .cell { padding: 4px 8px; } :deep .data-table .hover .cell { border-left: 1px solid blue; border-right: 1px solid blue; } </style>
全局安裝vue3-dragscroll
npm install vue3-dragscroll
在main.ts文件內(nèi)引入
import { createApp } from 'vue' import '@/style/index.css' import App from './App.vue' import router from './router' import Vue3Dragscroll from 'vue3-dragscroll' import ElementPlus from 'element-plus' import 'element-plus/dist/index.css' const app = createApp(App) app.use(createPinia()) app.use(router) app.use(ElementPlus, { locale: zhCn }) app.use(Vue3Dragscroll) app.mount('#app')
以上就是vue3鼠標(biāo)拖拽滑動(dòng)效果實(shí)現(xiàn)demo的詳細(xì)內(nèi)容,更多關(guān)于vue3鼠標(biāo)拖拽滑動(dòng)的資料請(qǐng)關(guān)注腳本之家其它相關(guān)文章!
相關(guān)文章
Vue實(shí)現(xiàn)手機(jī)號(hào)、驗(yàn)證碼登錄(60s禁用倒計(jì)時(shí))
這篇文章主要介紹了Vue實(shí)現(xiàn)手機(jī)號(hào)、驗(yàn)證碼登錄(60s禁用倒計(jì)時(shí)),幫助大家更好的理解和使用vue,感興趣的朋友可以了解下2020-12-12前端Vue3引入高德地圖并展示行駛軌跡動(dòng)畫(huà)的步驟
最近在Vue項(xiàng)目中引入高德地圖,實(shí)現(xiàn)地圖展示與交互的方法和技術(shù),這里跟大家分享下,這篇文章主要給大家介紹了關(guān)于前端Vue3引入高德地圖并展示行駛軌跡動(dòng)畫(huà)的相關(guān)資料,需要的朋友可以參考下2024-09-09如何解決element-ui動(dòng)態(tài)加載級(jí)聯(lián)選擇器默認(rèn)選中問(wèn)題
這篇文章主要介紹了如何解決element-ui動(dòng)態(tài)加載級(jí)聯(lián)選擇器默認(rèn)選中問(wèn)題,文章圍繞主題展開(kāi)詳細(xì)的內(nèi)容介紹,具有一定的參考價(jià)值,需要的朋友可以參考一下2022-09-09Vue3實(shí)現(xiàn)檢測(cè)密碼強(qiáng)度值功能
本文將演示如何使用Vue?3實(shí)現(xiàn)一個(gè)簡(jiǎn)單的密碼強(qiáng)度檢測(cè)功能,通過(guò)實(shí)時(shí)反饋,幫助用戶創(chuàng)建更安全的密碼,從而提升整體系統(tǒng)的安全性,需要的朋友可以參考下2024-06-06Vue3中的ref和reactive響應(yīng)式原理解析
這篇文章主要介紹了Vue3中的ref和reactive響應(yīng)式,本節(jié)主要介紹了響應(yīng)式變量和對(duì)象,以及變量和對(duì)象在響應(yīng)式和非響應(yīng)式之間的轉(zhuǎn)換,需要的朋友可以參考下2022-08-08vue3使用自定義hooks獲取dom元素的問(wèn)題說(shuō)明
這篇文章主要介紹了vue3使用自定義hooks獲取dom元素的問(wèn)題說(shuō)明,具有很好的參考價(jià)值,希望對(duì)大家有所幫助。如有錯(cuò)誤或未考慮完全的地方,望不吝賜教2022-04-04