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

JS method to determine whether scroll bar appears on the page_javascript skills

WBOY
Release: 2016-05-16 15:50:10
Original
1075 people have browsed it

The example in this article describes the method of JS to determine whether a scroll bar appears on the page. Share it with everyone for your reference. The details are as follows:

var isScroll = function (el) {
   // test targets
   var elems = el ? [el] : [document.documentElement, document.body];
   var scrollX = false, scrollY = false;
   for (var i = 0; i < elems.length; i++) {
     var o = elems[i];
     // test horizontal
     var sl = o.scrollLeft;
     o.scrollLeft += (sl > 0) &#63; -1 : 1;
     o.scrollLeft !== sl && (scrollX = scrollX || true);
     o.scrollLeft = sl;
     // test vertical
     var st = o.scrollTop;
     o.scrollTop += (st > 0) &#63; -1 : 1;
     o.scrollTop !== st && (scrollY = scrollY || true);
     o.scrollTop = st;
   }
   // ret
   return {
     scrollX: scrollX,
     scrollY: scrollY
   };
 };

Copy after login

I hope this article will be helpful to everyone’s JavaScript programming design.

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