您的位置:首页 > 运维架构 > 网站架构

做网站经常会用到的一些js效果

2017-11-27 10:54 429 查看
1.返回顶部
   $(function(){
        $('.top').hide();
        $(window).scroll(function() {       
             if($(window).scrollTop() >= 100){
                $('.top').fadeIn(300); 
                 }else{  $('.top').fadeOut(300);  }  
         });
        $('.top').click(function(){$('html,body').animate({scrollTop: '0px'}, 800);});
     });
2.点击锚点移动到对应的位置
   $(".aa").click(function(event){
        event.preventDefault(); //取消事件的默认动作。
        $('html,body').animate({scrollTop:$(this.hash).offset().top},800);
   });
3.判断页面加载是否完成
   document.onreadystatechange = loadingChange;//当页面加载状态改变的时候执行这个方法.  
        function loadingChange() {   
            if(document.readyState == "complete"){ //当页面加载状态为完全结束时进入   
                $(".loading").hide();//当页面加载完成后将loading页隐藏  
                window.location.href="http://www.baidu.com";
            }   
        }
4.禁止鼠标右键
   $(document).ready(function(){
        $(document).on("contextmenu",function(e){
             return false;
         });
    });
5.判断是pc端还是移动端
    function getClientInfo(){  
         var banner=document.getElementById('banner');
         var userAgentInfo = navigator.userAgent;  
         var Agents = new Array("Android", "iPhone", "SymbianOS", "Windows Phone", "iPad", "iPod");  
         var agentinfo = null;  
         for (var i = 0; i < Agents.length; i++) {  
                   if (userAgentInfo.indexOf(Agents[i]) > 0) { agentinfo = userAgentInfo; break; }  
         }  
         if(agentinfo){
                   $('.banner').css('height','auto');
                    banner.style.height='auto'
                   }else{
                        $('.banner').css($(window).height());
                        banner.style.height=document.body.clientHeight
                   }     
        }
6.判断是否是ie浏览器
   function isIE() { //ie?    
       if (!!window.ActiveXObject || "ActiveXObject" in window){
              return true;
         }else{}         
          return false;  
     } 
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签:  javascript jquery