Home >Web Front-end >JS Tutorial >JS method to determine whether scroll bar appears on the page_javascript skills
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) ? -1 : 1; o.scrollLeft !== sl && (scrollX = scrollX || true); o.scrollLeft = sl; // test vertical var st = o.scrollTop; o.scrollTop += (st > 0) ? -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.