【发布时间】:2020-06-09 22:49:28
【问题描述】:
【问题讨论】:
-
我使用你的 jsfiddle 实现了
scrollIntoView()方法来扩展我的答案。
标签: javascript html css wordpress
【问题讨论】:
scrollIntoView() 方法来扩展我的答案。
标签: javascript html css wordpress
滚动到特定数量的像素:jsFiddle
var body = document.body; // Safari
var html = document.documentElement; // Chrome, Firefox, IE and Opera places the overflow at the <html> level, unless else is specified. Therefore, we use the documentElement property for these browsers
body.scrollTop += 100;
html.scrollTop += 100;
滚动到一个元素:jsFiddle
var elmnt = document.getElementById("scroll");
elmnt.scrollIntoView();
以您的 jsFiddle 为例,在函数之外声明变量,使其具有全局性。