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

jquery method to determine whether scroll bar appears

藏色散人
藏色散人Original
2020-12-14 10:14:403203browse

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;)
}

Using native JavaScript writing method

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

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!

Statement:
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