亚洲在线久爱草,狠狠天天香蕉网,天天搞日日干久草,伊人亚洲日本欧美

為了賬號安全,請及時綁定郵箱和手機立即綁定
已解決430363個問題,去搜搜看,總會有你想問的

如何只滾動固定區域,而不是整個頁面 onClick?

如何只滾動固定區域,而不是整個頁面 onClick?

素胚勾勒不出你 2023-02-24 16:42:06
基本上,我有一個固定位置的 div,我需要在點擊時滾動而不是整個頁面。有一個 div 包含項目列表和它右側的向上/向下按鈕。頁面本身不滾動,但項目的 div 可以滾動 ( overflow-y: scroll),我想通過單擊來實現。有沒有辦法做到這一點?對不起,如果我的問題不夠清楚!編輯:這是小提琴的鏈接:https ://jsfiddle.net/yjphLeg0/4/單擊“向上”按鈕時,我希望div“div”的 with 和 id 向上滾動,“向下”按鈕和向下滾動相同。
查看完整描述

2 回答

?
catspeake

TA貢獻1111條經驗 獲得超0個贊

function move_down() {

document.getElementById('mydiv').scrollTop += 10;

}


function move_up() {

document.getElementById('mydiv').scrollTop -= 10;

}

使用上/下按鈕觸發功能。


查看完整回答
反對 回復 2023-02-24
?
鳳凰求蠱

TA貢獻1825條經驗 獲得超4個贊

function scrollWithin(wrapperElementId, innerElementId) {

  // get the inner element

  var innerElement = document.getElementById(innerElementId);

  // calculate the offset top to to wrapper element plus the element height

  var topPos = innerElement.offsetTop + (innerElement.offsetHeight / 2);

  // zoom the wrapper element to the inner element

  document.getElementById(wrapperElementId).scrollTop = topPos;

}


scrollWithin('scrollable', 'item3');


希望我明白你的意思。這是要測試的小提琴:https://jsfiddle.net/ukhzxs59/


查看完整回答
反對 回復 2023-02-24
  • 2 回答
  • 0 關注
  • 155 瀏覽
慕課專欄
更多

添加回答

舉報

0/150
提交
取消
微信客服

購課補貼
聯系客服咨詢優惠詳情

幫助反饋 APP下載

慕課網APP
您的移動學習伙伴

公眾號

掃描二維碼
關注慕課網微信公眾號