Home>Article>Web Front-end> jquery method to determine whether scroll bar appears
Jquery method to determine whether a scroll bar appears: 1. Use the "if ($(window).height() < $(document).height() ){}" method to determine whether the visible area exceeds Actual height; 2. Use the if statement to determine the height of the available work area on the screen.
The operating environment of this tutorial: windows7 system, jquery1.10.0 version, thinkpad t480 computer.
Recommended: "jquery video tutorial"
jquery determines whether a scroll bar appears
1. Determine whether the visible area is Exceeds the actual height and exceeds a certain level
if ($(window).height() < $(document).height() ) { alert('出现滚动条') }
Using native JavaScript writing method
if (document.documentElement.clientHeight < document.documentElement.offsetHeight){ alert('出现滚动条') }
2. Screen available work area height>=visible area of web page
if (window.screen.availHeight >= document.body.clientHeight) { alert("页面无滚动条") } else { alert("页面有滚动条") }
Note:
● $(window).height() // The height of the browser window’s visible area
document.documentElement.clientHeight
● $(document).height() // The height of the browser window document
document.documentElement.offsetHeight
● window.screen.availHeight // The height of the available work area on the screen
● document.body.clientHeight // Visible area of web page
The above is the detailed content of jquery method to determine whether scroll bar appears. For more information, please follow other related articles on the PHP Chinese website!