JS 一些功能代码块[如判断设备]

判断是否为PC

来源:http://blog.csdn.net/seven1276/article/details/8211877

function IsPC()  
       {  
           var userAgentInfo = navigator.userAgent;  
           var Agents = new Array("Android", "iPhone", "SymbianOS", "Windows Phone", "iPad", "iPod");  
           var flag = true;  
           for (var v = 0; v < Agents.length; v++) {  
               if (userAgentInfo.indexOf(Agents[v]) > 0) { flag = false; break; }  
           }  
           return flag;  
       }  

 获取滚动条距顶部距离  返回 number

function getScrollTop() {
                var scrollPos;
                if (window.pageYOffset) {
                    scrollPos = window.pageYOffset;
                } else if (document.compatMode && document.compatMode != 'BackCompat') {
                    scrollPos = document.documentElement.scrollTop;
                } else if (document.body) { scrollPos = document.body.scrollTop;
                }
                return scrollPos;
            }

 

posted @ 2014-07-26 09:27  会敲代码的狼  阅读(157)  评论(0编辑  收藏  举报