Home  >  Article  >  Web Front-end  >  JS method to determine whether scroll bar appears on the page_javascript skills

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

WBOY
WBOYOriginal
2016-05-16 15:50:101058browse

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
   };
 };

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

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