欧美bbbwbbbw肥妇,免费乱码人妻系列日韩,一级黄片

js返回頂部實例分享

 更新時間:2016年12月21日 11:06:26   作者:以茜為貴  
本文主要分享了js返回頂部的實例代碼。可復制直接運行,方便快捷。有很好的參考價值,需要的朋友一起來看下吧

話不多說,請看實例

1、HTML結構

<div class="return_top"></div>

2、css樣式

.return_top{ 
  width: 50px; 
  height: 50px; 
  background: url(../images/lanren.gif) no-repeat center #FF8D16; 
  position:fixed; 
  right: 30px; 
  bottom: 30px; 
  display: none; 
  cursor: pointer; 
  z-index: 99;
}

3、js效果

<script>
   $(function(){
    $(window).scroll(function(){
      var topDistance=$(window).scrollTop();  //獲取鼠標在本窗口現(xiàn)有狀態(tài)下移動的高度
      if(topDistance>100){  //如果移動高度大于100px,頂部圖標單單顯示出,如果移動高度小于等于100,頂部圖標不顯示
        $('.return_top').fadeIn(800);
      }else{
        $('.return_top').fadeOut(800);
      }
    });
    $('.return_top').on('click',function(){
      $('html,body').animate({scrollTop:0},800); //必須用$('html,body')選擇,不然沒效果
    })
  });
</script>

以上就是本文的全部內(nèi)容,希望本文的內(nèi)容對大家的學習或者工作能帶來一定的幫助,同時也希望多多支持腳本之家!

相關文章

最新評論