Home > Web Front-end > JS Tutorial > jQuery method to determine whether scroll bar exists

jQuery method to determine whether scroll bar exists

藏色散人
Release: 2023-01-04 09:36:52
Original
2721 people have browsed it

How jQuery determines whether a scroll bar exists: First create a front-end code sample file; then use jQuery to control the scroll bar scrolling; finally pass "if( $("body").scrollTop()>0) {...}else{...}" statement can be used to determine whether the scroll bar is offset.

jQuery method to determine whether scroll bar exists

#The operating environment of this tutorial: Windows 7 system, jquery1.10.0 version, thinkpad t480 computer.

Recommended: jquery video tutorial

jQuery determines whether there is a scroll bar

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.

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

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