本文实例讲述了JS判断页面是否出现滚动条的方法。分享给大家供大家参考。具体如下:
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 }; };
希望本文所述对大家的javascript程序设计有所帮助。
新闻热点
疑难解答