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
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.
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!