亚洲乱码中文字幕综合,中国熟女仑乱hd,亚洲精品乱拍国产一区二区三区,一本大道卡一卡二卡三乱码全集资源,又粗又黄又硬又爽的免费视频

vue3手動(dòng)設(shè)置滾動(dòng)條位置自動(dòng)定位功能

 更新時(shí)間:2024年12月12日 12:15:46   作者:m0_74824592  
這篇文章介紹了vue3手動(dòng)設(shè)置滾動(dòng)條位置自動(dòng)定位功能,本文通過(guò)實(shí)例代碼給大家介紹的非常詳細(xì),感興趣的朋友跟隨小編一起看看吧

從B頁(yè)面進(jìn)行xx操作后需要跳轉(zhuǎn)到A頁(yè)面,并定位到AA職位,上圖為A頁(yè)面。

A頁(yè)面的左側(cè)是div,內(nèi)層包裹List組件

給div定義ref=leftRef,在代碼中寫(xiě)如下:

? function scrollTop() {
? ? if (leftRef.value) {
? ? ? console.log('99', leftRef.value);
? ? ? nextTick(() => {
? ? ? ? leftRef.value.scrollTop = 1000;
? ? ? ? // scrollBy(0, document.body.scrollWidth);
? ? ? });
? ? }
? }
onMounted(async () => {
? ? if (router.currentRoute.value.query.id) {
? ? ? positionChooseCode.value = router.currentRoute.value.query.id;
? ? ? positionStatusValue.value = router.currentRoute.value.query.id;
? ? }
? ? const positionId = router.currentRoute.value.query.positionId;
? ? if (!!positionId) {
? ? ? cStore.setPositionId(positionId);
? ? }
? ? console.log('mounted--positionId', positionId);
? ? await getPositionDictionary(positionChooseCode.value, '');
? ? await getDictionaries();
? ? scrollTop();
? });

第一,需要等待數(shù)據(jù)渲染完成后,再調(diào)用scrollTop,設(shè)置scrollTop=1000,這樣頁(yè)面初始化滾動(dòng)條位置會(huì)改變。

第二,找到當(dāng)前職位的高度,也要等職位列表數(shù)據(jù)渲染完成后,獲取

? ? console.log('positionList.value', positionList.value);
? ? rowItemId.value = item.id;
? ? //找到前面有多少個(gè)元素
? ? let index = positionList.value.findIndex((it) => it.id === rowItemId.value);
? ? console.log('找到前面有多少個(gè)元素', index + 1);
? ? num.value = index - 2;
獲取當(dāng)前職位,當(dāng)前職位會(huì)有class==red的,通過(guò)class獲取ele;
?const sortableEles = document.querySelectorAll('.red');
? ? ? console.log(sortableEles);
? ? ? let itemHeight = 0;
? ? ? if (sortableEles.length > 0) {
? ? ? ? const firstListItem = sortableEles[0];
? ? ? ? itemHeight = firstListItem.offsetHeight; // 獲取元素的高度,包括內(nèi)邊距和邊框
? ? ? ? console.log('第一個(gè)列表項(xiàng)的高度:', itemHeight);
? ? ? ? console.log(' num.value', num.value);
? ? ? }

完整的scrollTop方法如下

總結(jié):

滾動(dòng)條要滾動(dòng)起來(lái)
選中含有滾動(dòng)條的元素,定義一個(gè)const leftRef = ref(null),在數(shù)據(jù)加載完成后設(shè)置leftRef.value.scrollTop

滾動(dòng)條的位置
等待數(shù)據(jù)加載完后獲取當(dāng)前選中的元素,通過(guò).offsetHeight獲取元素的高度

到此這篇關(guān)于vue3手動(dòng)設(shè)置滾動(dòng)條位置自動(dòng)定位功能的文章就介紹到這了,更多相關(guān)vue手動(dòng)設(shè)置滾動(dòng)條內(nèi)容請(qǐng)搜索腳本之家以前的文章或繼續(xù)瀏覽下面的相關(guān)文章希望大家以后多多支持腳本之家!

相關(guān)文章

最新評(píng)論