📅  最后修改于: 2023-12-03 15:32:09.694000             🧑  作者: Mango
jQuery scrollHeight is a property that returns the total height of an element's content, including its padding, but not including its border and margin. This property is only applicable to elements that have overflowing content such as
The jQuery scrollHeight property syntax is as follows:
$(selector).prop("scrollHeight");
The jQuery scrollHeight property does not require any parameters.
The jQuery scrollHeight property returns the height of an element's content as an integer value.
<div id="myDiv" style="height:100px; border:1px solid black; overflow:auto;">
Lorem ipsum dolor sit amet, consectetur adipiscing elit. Vivamus a finibus nunc. Nam id tincidunt urna. Proin ligula nibh, tristique vel velit sed, faucibus accumsan magna. Curabitur nec vestibulum magna. Nunc ac venenatis nisi, in venenatis ante.
</div>
var myDivScrollHeight = $("#myDiv").prop("scrollHeight");
console.log("The scroll height of myDiv is: " + myDivScrollHeight);
<textarea id="myTextarea" style="height:100px; border:1px solid black; overflow:auto;">
Lorem ipsum dolor sit amet, consectetur adipiscing elit. Vivamus a finibus nunc. Nam id tincidunt urna. Proin ligula nibh, tristique vel velit sed, faucibus accumsan magna. Curabitur nec vestibulum magna. Nunc ac venenatis nisi, in venenatis ante.
</textarea>
$(document).ready(function(){
$("#myTextarea").scrollTop($("#myTextarea").prop("scrollHeight"));
});
jQuery scrollHeight is a useful property for getting the height of an element's content, which can be used for various purposes such as setting the height of an element dynamically or scrolling to a specific location within an element.