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

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;  
     } 
  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值