Home > Web Front-end > JS Tutorial > body text

How to determine whether the scroll bar exists in jquery

王林
Release: 2020-11-30 17:21:33
Original
2265 people have browsed it

Jquery method to determine whether the scroll bar exists: first use jquery to control the scroll bar scrolling; then determine whether the scroll bar is offset. If there is an offset, it means that the scroll bar exists. Otherwise, it means that the scroll bar does not exist. exist.

How to determine whether the scroll bar exists in jquery

The operating environment of this tutorial: Windows 7 system, jquery version 1.10.0. This article is applicable to all brands of computers.

Judgment idea:

Use jQuery to control the scroll bar scrolling, and then determine whether the scroll bar is offset. If there is, the scroll bar exists, otherwise it does not exist without scrolling.

(Learning video sharing: jquery video tutorial)

Code implementation:

<script type="text/javascript">
$(function(){
    $("body").scrollTop(10);//控制滚动条下移10px
    if( $("body").scrollTop()>0 ){
        alert("有滚动条");
    }else{
        alert("没有滚动条");
    }
    $("body").scrollTop(0);//滚动条返回顶部
});
</script>
Copy after login

Related recommendations: js tutorial

The above is the detailed content of How to determine whether the scroll bar exists in jquery. 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