获得滚动值不输出

时间:2017-12-05 18:36:10

标签: javascript html google-chrome dom

为什么滚动输出的值是未定义的?我正在使用chrome进行扩展。

var scroll = document.body.scrollTop;
console.log(scroll);

1 个答案:

答案 0 :(得分:0)

W3C文档位于:

Open Source Load Testing Tools: Which One Should You Use?

来自文档:

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.scrollLeft += 30;
body.scrollTop += 10;
html.scrollLeft += 30;
html.scrollTop += 10;