vue.js滾動條插件vue-scroll的基本用法
1)介紹
vuescroll 是一個基于 vue.js 2.X虛擬滾動條, 它支持定制滾動條的樣式,檢測內(nèi)容尺寸變化、能夠使內(nèi)容分頁、支持上拉-刷新,下推加載等諸多特性
2)特點(diǎn)
(1)擁有原生滾動條的滾動行為
(2)可以定制滾動條的樣式(包括顏色、尺寸、位置、透明度、是否保持顯示等)
(3)在模式之間自由切換
(4)能夠通過設(shè)置滾動動畫來平滑地滾動
(5)拉取刷新和推動加載
(6)支持分頁模式(每次滑動整個頁面)
(7)支持快照模式(每次滑動滾動一個用戶定義的距離)
(8)可以檢測內(nèi)容尺寸發(fā)生變化
3)用法
(1)安裝
npm install vuescroll -S
(2)使用
①入口文件配置
import Vue from 'vue'
import vuescroll from 'vuescroll'
Vue.use(vuescroll)
const vm = new Vue({ el: "#app", data: { ops: { vuescroll: { }, scrollPanel: { } // ... } } })
②或在需要的頁面引入
import vueScroll from "vuescroll";
在components中再注冊一下
components:{vueScroll,}
這兩種引入方式都可以,引入后用vuescroll包裹需要滾動的部分
<div id="app" >
<vue-scroll :ops="ops">
<div class="content" v-for= "item in 100" :key="item" >
<span>{{item}}</span>
</div>
</vue-scroll>
</div>
③配置
在data中寫明需要修改的配置項(xiàng)
data(){
return{
// 滾動條的配置信息
ops:{
vueScroll:{},
scrollPanel:{},
rail:{
opacity:'0.1',
border:'1px solid #f2f2f2',
size:'6px'
},
bar:{
size:'6px',
background:'#999',
keepShow:true,
}
},}}
④配置項(xiàng)匯總
export default {
// vuescroll vuescroll: {
mode: 'native',
// 設(shè)置 vuescroll的大小類型, 可選的有percent, number.
// 設(shè)置為percent會把 vuescroll 的 height 和 width 設(shè)置成100%,
// 設(shè)置成number的話 vuescroll 會自動計算父元素的大小,并將height和width設(shè)置成對應(yīng)的數(shù)值。
// 提示:如果父元素的尺寸為百分比大小時建議設(shè)置成number,如果父元素大小為一個固定的px的值,那么設(shè)置為百分比比較合適一些。
sizeStrategy: 'percent',
// 是否開啟監(jiān)聽 dom resize
detectResize: true,
// 下拉刷新相關(guān)(slide mode) pullRefresh: {
enable: false,
// 下拉刷新的提示
tips: {
deactive: 'Pull to Refresh',
active: 'Release to Refresh',
start: 'Refreshing...',
beforeDeactive: 'Refresh Successfully!'
}
},
// 上推加載相關(guān)
pushLoad: {
enable: false,
tips: {
deactive: 'Push to Load',
active: 'Release to Load',
start: 'Loading...',
beforeDeactive: 'Load Successfully!'
},
auto: false,
autoLoadDistance: 0
},
paging: false,
zooming: true,
// 快照
snapping: {
enable: false,
width: 100,
height: 100
},
/* shipped scroll options */
scroller: {
/*
允許滾動出邊界
true 或者 false 或者一個數(shù)組指定哪個方向可以超出邊界,可選項(xiàng)分別是:
['top','bottom','left','right']
*/
bouncing: true,
/** Enable locking to the main axis if user moves only slightly on one of them at start */
locking: true,
/** 最小縮放級別 */
minZoom: 0.5,
/** 最大縮放級別 */
maxZoom: 3,
/** 滾動速度的倍速 **/
speedMultiplier: 1,
/** 到達(dá)邊界時應(yīng)用于減速的改變量 **/
penetrationDeceleration: 0.03,
/** 到達(dá)邊界時應(yīng)用于加速的改變量 **/
penetrationAcceleration: 0.08,
/** Whether call e.preventDefault event when sliding the content or not */
preventDefault: true,
/** Whether call preventDefault when (mouse/touch)move*/
preventDefaultOnMove: true
}
},
scrollPanel: {
// 組件加載完后的初始滾動量
initialScrollY: false,
initialScrollX: false,
// 是否禁止x或y方向上的滾動
scrollingX: true,
scrollingY: true,
speed: 300,
// 滾動動畫
easing: undefined,
// 是否有一個padding樣式,樣式的大小應(yīng)該和rail/bar的大小是一樣??梢杂脕碜柚箖?nèi)容被滾動條遮住一部分
padding: false,
// 有時候原聲滾動條可能在左側(cè),
// 請查看 https://github.com/YvesCoding/vuescroll/issues/64
verticalNativeBarPos: 'right'
},
//滾動條滾動的地方 rail: {
background: '#01a99a',
opacity: 0,
border: 'none',
/** Rail's size(Height/Width) , default -> 6px */
size: '6px',
/** Specify rail's border-radius, or the border-radius of rail and bar will be equal to the rail's size. default -> false **/
specifyBorderRadius: false,
/** Rail the distance from the two ends of the X axis and Y axis. **/
gutterOfEnds: null,
/** Rail the distance from the side of container. **/
gutterOfSide: '2px',
/** Whether to keep rail show or not, default -> false, event content height is not enough */
keepShow: false
},
bar: {
/** 當(dāng)不做任何操作時滾動條自動消失的時間 */
showDelay: 500,
/** Specify bar's border-radius, or the border-radius of rail and bar will be equal to the rail's size. default -> false **/
specifyBorderRadius: false,
/** 是否只在滾動的時候現(xiàn)實(shí)滾動條 */
onlyShowBarOnScroll: true,
/** 是否保持顯示 */
keepShow: false,
/** 滾動條顏色, default -> #00a650 */
background: 'rgb(3, 185, 118)',
/** 滾動條透明度, default -> 1 */
opacity: 1,
/** Styles when you hover scrollbar, it will merge into the current style */
hoverStyle: false
},
scrollButton: {
enable: false,
background: 'rgb(3, 185, 118)',
opacity: 1,
step: 180,
mousedownStep: 30
}
};補(bǔ)充:vue-scroll中的@handle-scroll方法



綜上
得出滾動條到達(dá)底部的計算公式為:clientHeight + scrollTop == scrollHeight,知道這個之后,我們寫邏輯就容易多了,只需要在滾動條到達(dá)底部的時候,重新取獲取數(shù)據(jù)就可以了

總結(jié)
到此這篇關(guān)于vue.js滾動條插件vue-scroll的基本用法的文章就介紹到這了,更多相關(guān)滾動條插件vue-scroll內(nèi)容請搜索腳本之家以前的文章或繼續(xù)瀏覽下面的相關(guān)文章希望大家以后多多支持腳本之家!
相關(guān)文章
uniapp實(shí)現(xiàn)紅包動畫效果代碼實(shí)例(vue3)
uniapp作為一種基于Vue.js的前端框架,實(shí)現(xiàn)了一套代碼多端運(yùn)行的理念,成為了眾多開發(fā)者的首選,下面這篇文章主要給大家介紹了關(guān)于uniapp實(shí)現(xiàn)紅包動畫效果的相關(guān)資料,需要的朋友可以參考下2024-01-01
Element實(shí)現(xiàn)登錄+注冊的示例代碼
登錄注冊是最常用的網(wǎng)站功能,本文主要介紹了Element實(shí)現(xiàn)登錄+注冊的示例代碼,具有一定的參考價值,感興趣的可以了解一下2023-09-09
Fragment 占位組件不生成標(biāo)簽與路由組件lazyLoad案例
這篇文章主要為大家介紹了Fragment 占位組件不生成標(biāo)簽與路由組件lazyLoad案例詳解,有需要的朋友可以借鑒參考下,希望能夠有所幫助,祝大家多多進(jìn)步,早日升職加薪2022-10-10
Vue.set()實(shí)現(xiàn)數(shù)據(jù)動態(tài)響應(yīng)的方法
這篇文章主要介紹了Vue.set()實(shí)現(xiàn)數(shù)據(jù)動態(tài)響應(yīng)的相關(guān)知識,非常不錯,具有參考借鑒價值,需要的朋友可以參考下2018-02-02
基于Element-Ui封裝公共表格組件的詳細(xì)圖文步驟
在平時開發(fā)的時候很多情況都會使用到表格和分頁功能,下面這篇文章主要給大家介紹了關(guān)于如何基于Element-Ui封裝公共表格組件的詳細(xì)圖文步驟,需要的朋友可以參考下2022-09-09
Vue實(shí)現(xiàn)導(dǎo)出excel表格功能
這篇文章主要介紹了Vue實(shí)現(xiàn)導(dǎo)出excel表格的功能,在文章末尾給大家提到了vue中excel表格的導(dǎo)入和導(dǎo)出代碼,需要的朋友可以參考下2018-03-03
vue3中使用pinia(大菠蘿)狀態(tài)管理倉庫的項(xiàng)目實(shí)踐
本文主要介紹了vue3中使用pinia(大菠蘿)狀態(tài)管理倉庫,文中通過示例代碼介紹的非常詳細(xì),對大家的學(xué)習(xí)或者工作具有一定的參考學(xué)習(xí)價值,需要的朋友們下面隨著小編來一起學(xué)習(xí)學(xué)習(xí)吧2023-07-07
vue開發(fā)利器之unplugin-auto-import的使用
unplugin-auto-import 解決了vue3-hook、vue-router、useVue等多個插件的自動導(dǎo)入,也支持自定義插件的自動導(dǎo)入,下面這篇文章主要給大家介紹了關(guān)于vue開發(fā)利器之unplugin-auto-import使用的相關(guān)資料,需要的朋友可以參考下2023-02-02

