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

js返回頂部實(shí)例分享

 更新時(shí)間:2016年12月21日 11:06:26   作者:以茜為貴  
本文主要分享了js返回頂部的實(shí)例代碼??蓮?fù)制直接運(yùn)行,方便快捷。有很好的參考價(jià)值,需要的朋友一起來(lái)看下吧

話不多說(shuō),請(qǐng)看實(shí)例

1、HTML結(jié)構(gòu)

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

以上就是本文的全部?jī)?nèi)容,希望本文的內(nèi)容對(duì)大家的學(xué)習(xí)或者工作能帶來(lái)一定的幫助,同時(shí)也希望多多支持腳本之家!

相關(guān)文章

最新評(píng)論