0)" statement to determine whether the scroll bar is biased Shift; if there is an offset, a scroll bar exists, otherwise it does not exist without scrolling."/> 0)" statement to determine whether the scroll bar is biased Shift; if there is an offset, a scroll bar exists, otherwise it does not exist without scrolling.">

Home >Web Front-end >JS Tutorial >How to determine whether an element has scroll bars in jquery

How to determine whether an element has scroll bars in jquery

coldplay.xixi
coldplay.xixiOriginal
2020-12-03 09:28:333023browse

Judgment method: First use the "$("body").scrollTop(10)" statement to control the scroll bar scrolling, and then use "if( $("body").scrollTop()>0)" The statement determines whether the scroll bar is offset; if there is an offset, the scroll bar exists. On the contrary, it does not exist without scrolling.

How to determine whether an element has scroll bars in jquery

The operating environment of this tutorial: windows7 system, jquery3.2.1 version, Dell G3 computer.

How jquery determines whether an element has 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>

Related learning recommendations: javascript video tutorial

The above is the detailed content of How to determine whether an element has scroll bars in jquery. 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