日韩性视频-久久久蜜桃-www中文字幕-在线中文字幕av-亚洲欧美一区二区三区四区-撸久久-香蕉视频一区-久久无码精品丰满人妻-国产高潮av-激情福利社-日韩av网址大全-国产精品久久999-日本五十路在线-性欧美在线-久久99精品波多结衣一区-男女午夜免费视频-黑人极品ⅴideos精品欧美棵-人人妻人人澡人人爽精品欧美一区-日韩一区在线看-欧美a级在线免费观看

歡迎訪問 生活随笔!

生活随笔

當前位置: 首頁 > 前端技术 > vue >内容正文

vue

html任务3 模拟滚动条,vue3系列:vue3.0自定义虚拟滚动条V3Scroll|vue3模拟滚动条组件...

發布時間:2024/9/19 vue 28 豆豆
生活随笔 收集整理的這篇文章主要介紹了 html任务3 模拟滚动条,vue3系列:vue3.0自定义虚拟滚动条V3Scroll|vue3模拟滚动条组件... 小編覺得挺不錯的,現在分享給大家,幫大家做個參考.

/**

* @Desc Vue3.0虛擬滾動條組件V3Scroll

* @Time andy by 2021-01

* @About Q:282310962 wx:xy190310*/

props: {//...

},/**

* Vue3.x自定義指令寫法*/

//監聽DOM尺寸變化

directives: {'resize': {

beforeMount:function(el, binding) {

let width= '', height = '';functionget() {

const elStyle= el.currentStyle ? el.currentStyle : document.defaultView.getComputedStyle(el, null);if (width !== elStyle.width || height !==elStyle.height) {

binding.value({width, height});

}

width=elStyle.width;

height=elStyle.height;

}

el.__vueReize__= setInterval(get, 16);

},

unmounted:function(el) {

clearInterval(el.__vueReize__);

}

}

},

setup(props, context) {

const ref__box= ref(null)

const ref__wrap= ref(null)

const ref__barX= ref(null)

const ref__barY= ref(null)

const data=reactive({

barWidth:0, //滾動條寬度

barHeight: 0, //滾動條高度

ratioX: 1, //滾動條水平偏移率

ratioY: 1, //滾動條垂直偏移率

isTaped: false, //鼠標光標是否按住滾動條

isHover: false, //鼠標光標是否懸停在滾動區

isShow: !props.autohide, //是否顯示滾動條

})

onMounted(()=>{

nextTick(()=>{

updated()

})

})//鼠標滑入

const handleMouseEnter = () =>{

data.isHover= truedata.isShow= trueupdated()

}//鼠標滑出

const handleMouseLeave = () =>{

data.isHover= falsedata.isShow= false}//拖動滾動條

const handleDragThumb = (e, index) =>{

const elWrap=ref__wrap.value

const elBarX=ref__barX.value

const elBarY=ref__barY.value

data.isTaped= truelet c={}//阻止默認事件

domUtils.isIE() ? (e.returnValue = false, e.cancelBubble = true) : (e.stopPropagation(), e.preventDefault())

document.onselectstart= () => false

if(index == 0) {

c.dragY= truec.clientY=e.clientY

}else{

c.dragX= truec.clientX=e.clientX

}//...

}//點擊滾動槽

const handleClickTrack = (e, index) =>{//...

}//更新滾動區

const updated = () =>{if(props.native) returnconst elBox=ref__box.value

const elWrap=ref__wrap.value

const elBarX=ref__barX.value

const elBarY=ref__barY.value

let barSize=domUtils.getScrollBarSize()//垂直滾動條

if(elWrap.scrollHeight >elWrap.offsetHeight) {

data.barHeight= elBox.offsetHeight **2 /elWrap.scrollHeight

data.ratioY= (elWrap.scrollHeight - elBox.offsetHeight) / (elBox.offsetHeight -data.barHeight)

elBarY.style.transform= `translateY(${elWrap.scrollTop /data.ratioY}px)`//隱藏系統滾動條

if(barSize) {

elWrap.style.marginRight= -barSize + 'px'}

}else{

data.barHeight= 0elBarY.style.transform= ''elWrap.style.marginRight= ''}//水平滾動條

//...

}//滾動區元素/DOM尺寸改變

const handleResize = () =>{//執行更新操做

}//...

return{

...toRefs(data),

ref__box, ref__wrap, ref__barX, ref__barY,

handleMouseEnter, handleMouseLeave,

handleDragThumb, handleClickTrack,

updated,//...

}

}

}

總結

以上是生活随笔為你收集整理的html任务3 模拟滚动条,vue3系列:vue3.0自定义虚拟滚动条V3Scroll|vue3模拟滚动条组件...的全部內容,希望文章能夠幫你解決所遇到的問題。

如果覺得生活随笔網站內容還不錯,歡迎將生活随笔推薦給好友。