Posted in Javascript onJuly 17, 2015
本文实例讲述了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程序设计有所帮助。
JS判断页面是否出现滚动条的方法
- Author -
答复哈声明:登载此文出于传递更多信息之目的,并不意味着赞同其观点或证实其描述。
Reply on: @reply_date@
@reply_contents@