2 回答

TA貢獻1111條經驗 獲得超0個贊
function move_down() {
document.getElementById('mydiv').scrollTop += 10;
}
function move_up() {
document.getElementById('mydiv').scrollTop -= 10;
}
使用上/下按鈕觸發功能。

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/
添加回答
舉報