Home > Web Front-end > JS Tutorial > jquery method to determine whether scroll bar appears

jquery method to determine whether scroll bar appears

藏色散人
Release: 2021-01-22 16:41:03
Original
3272 people have browsed it

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.

jquery method to determine whether scroll bar appears

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(&#39;出现滚动条&#39;)
}
Copy after login

Using native JavaScript writing method

if (document.documentElement.clientHeight < document.documentElement.offsetHeight){
    alert(&#39;出现滚动条&#39;)
}
Copy after login

2. Screen available work area height>=visible area of ​​web page

if (window.screen.availHeight >= document.body.clientHeight) {
  alert("页面无滚动条")
} else {
    alert("页面有滚动条")
}
Copy after login

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!

Related labels:
source:php.cn
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template