私人领地

window.onscroll页面滚动条滚动事件

用途一:"返回顶部";

window.onscroll = function(){ 
    var t = document.documentElement.scrollTop || document.body.scrollTop;  
    var top_div = document.getElementById( "top_div" ); 
    if( t >= 300 ) { 
        top_div.style.display = "inline"; 
    } else { 
        top_div.style.display = "none"; 
    } 
} 

 

用途二:"商品详情菜单漂浮"  当鼠标滚动到一定位置 会有一个导航漂浮起来  

window.onscroll = function(){ 
      var t = document.documentElement.scrollTop || document.body.scrollTop;  
      var Div = document.getElementById( "fix_goods" ); 
      if( t <= 755 ) { 
          Div.style.position = "";
          Div.style.top = "";
      } else { 
          //Div.style.display = "none";
          Div.style.position = "fixed";
          Div.style.top = "-10px";
      
      } 
  }

 

原文来源:http://www.cnblogs.com/wesky/admin/EditPosts.aspx?postid=3303694&update=1

posted @ 2013-09-05 17:05  狂奔的蜗牛Snails  阅读(2600)  评论(0编辑  收藏  举报