vue.js滾動條插件vue-scroll的基本用法
1)介紹
vuescroll 是一個基于 vue.js 2.X虛擬滾動條, 它支持定制滾動條的樣式,檢測內(nèi)容尺寸變化、能夠使內(nèi)容分頁、支持上拉-刷新,下推加載等諸多特性
2)特點
(1)擁有原生滾動條的滾動行為
(2)可以定制滾動條的樣式(包括顏色、尺寸、位置、透明度、是否保持顯示等)
(3)在模式之間自由切換
(4)能夠通過設置滾動動畫來平滑地滾動
(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中寫明需要修改的配置項
data(){
return{
// 滾動條的配置信息
ops:{
vueScroll:{},
scrollPanel:{},
rail:{
opacity:'0.1',
border:'1px solid #f2f2f2',
size:'6px'
},
bar:{
size:'6px',
background:'#999',
keepShow:true,
}
},}}
④配置項匯總
export default {
// vuescroll vuescroll: {
mode: 'native',
// 設置 vuescroll的大小類型, 可選的有percent, number.
// 設置為percent會把 vuescroll 的 height 和 width 設置成100%,
// 設置成number的話 vuescroll 會自動計算父元素的大小,并將height和width設置成對應的數(shù)值。
// 提示:如果父元素的尺寸為百分比大小時建議設置成number,如果父元素大小為一個固定的px的值,那么設置為百分比比較合適一些。
sizeStrategy: 'percent',
// 是否開啟監(jiān)聽 dom resize
detectResize: true,
// 下拉刷新相關(slide mode) pullRefresh: {
enable: false,
// 下拉刷新的提示
tips: {
deactive: 'Pull to Refresh',
active: 'Release to Refresh',
start: 'Refreshing...',
beforeDeactive: 'Refresh Successfully!'
}
},
// 上推加載相關
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ù)組指定哪個方向可以超出邊界,可選項分別是:
['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,
/** 到達邊界時應用于減速的改變量 **/
penetrationDeceleration: 0.03,
/** 到達邊界時應用于加速的改變量 **/
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樣式,樣式的大小應該和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: {
/** 當不做任何操作時滾動條自動消失的時間 */
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)實滾動條 */
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
}
};補充:vue-scroll中的@handle-scroll方法



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

總結
到此這篇關于vue.js滾動條插件vue-scroll的基本用法的文章就介紹到這了,更多相關滾動條插件vue-scroll內(nèi)容請搜索腳本之家以前的文章或繼續(xù)瀏覽下面的相關文章希望大家以后多多支持腳本之家!
相關文章
vue3中處理不同數(shù)據(jù)結構JSON的實現(xiàn)
本文主要介紹了vue3中處理不同數(shù)據(jù)結構JSON的實現(xiàn),文中通過示例代碼介紹的非常詳細,對大家的學習或者工作具有一定的參考學習價值,需要的朋友們下面隨著小編來一起學習學習吧2023-06-06
vue3?+?async-validator實現(xiàn)表單驗證的示例代碼
表單驗證可以有效的過濾不合格的數(shù)據(jù),減少服務器的開銷,并提升用戶的使用體驗,今天我們使用?vue3?來做一個表單驗證的例子,需要的朋友跟隨小編一起學習下吧2022-06-06
vue-router配合ElementUI實現(xiàn)導航的實例
下面小編就為大家分享一篇vue-router配合ElementUI實現(xiàn)導航的實例,具有很好的參考價值,希望對大家有所幫助。一起跟隨小編過來看看吧2018-02-02

