Dem*_*wis 177
以下是如何scrollHeight获取使用jQuery选择器获取的元素:
$(selector)[0].scrollHeight
Run Code Online (Sandbox Code Playgroud)
如果selector是元素的id(例如elemId),则保证数组的0索引项将是您要选择的元素,并且scrollHeight将是正确的.
Bob*_*gor 46
$(document).height() //returns window height
$(document).scrollTop() //returns scroll position from top of document
Run Code Online (Sandbox Code Playgroud)
Ank*_*kit 45
如果您使用的是Jquery 1.6或更高版本,请使用prop访问该值.
$(document).prop('scrollHeight')
Run Code Online (Sandbox Code Playgroud)
以前的版本用于从attr获取值,但不是在1.6之后.
document.getElementById("elementID").scrollHeight
$("elementID").scrollHeight
Run Code Online (Sandbox Code Playgroud)
小智 6
它使用HTML DOM Elements,但不使用jQuery选择器.它可以像:
var height = document.body.scrollHeight;
Run Code Online (Sandbox Code Playgroud)