最新国产好看的视频,伊人天堂AV在线,国产Aaaaaa视频,蜜臀视频在线观看一区,人妻av色图,密臀久久久精品影片,青青视频免费观看毛片,久草在线观看视,国产三级精品色情在线

jQuery實(shí)現(xiàn)小火箭返回頂部特效

 更新時(shí)間:2020年02月03日 16:35:52   作者:jane_panyiyun  
這篇文章主要為大家詳細(xì)介紹了jQuery實(shí)現(xiàn)小火箭返回頂部特效,文中示例代碼介紹的非常詳細(xì),具有一定的參考價(jià)值,感興趣的小伙伴們可以參考一下

jquery實(shí)現(xiàn)小火箭返回頂部案例,供大家參考,具體內(nèi)容如下

1. 滾動(dòng)頁(yè)面,當(dāng)頁(yè)面距離頂部超出1000px,顯示小火箭。

封裝在scroll函數(shù)里,當(dāng)前頁(yè)面距離頂部為$(window).scrollTop >=1000

小火箭顯示和隱藏用fadeIn和fadeOut

//當(dāng)頁(yè)面超出1000px的時(shí)候,讓小火箭顯示,如果小于1000px,則隱藏
   $(window).scroll(function () {
    if ($(window).scrollTop() >= 1000) {
     $(".actGotop").stop().fadeIn(1000);
    } else {
     $(".actGotop").stop().fadeOut(1000);
    }
   })
});

2. 當(dāng)小火箭出現(xiàn)后,點(diǎn)擊小火箭,返回到頁(yè)面頂部。

在外面出冊(cè)點(diǎn)擊事件,獲取頁(yè)面,html或者body, 返回用animate動(dòng)畫(huà)函數(shù),到頂部即scrollTop為0,時(shí)間可以設(shè)置

$(".actGotop").click(function () {
   $("html,body").stop().animate({ scrollTop: 0 }, 1000);
  }); 

3. 如果要讓小火箭點(diǎn)擊后,直接回到頂部,可以只設(shè)置$(window).scrollTop(0),既可

$(".actGotop").click(function () {
   //$("html,body").stop().animate({ scrollTop: 0 }, 1000);
   //scrollTop為0
   $(window).scrollTop(0);
  });

整體代碼如下:

<!DOCTYPE html>
<html lang="en">

<head>
 <meta charset="UTF-8">
 <title>Title</title>
 <style>
  body {
   height: 8000px;
  }

  a {
   color: #FFF;
  }

  .actGotop {
   position: fixed;
   bottom: 50px;
   right: 50px;
   width: 150px;
   height: 195px;
   display: none;
   z-index: 100;
  }

  .actGotop a,
  .actGotop a:link {
   width: 150px;
   height: 195px;
   display: inline-block;
   background: url(images/gotop.png) no-repeat;
   outline: none;
  }

  .actGotop a:hover {
   width: 150px;
   height: 195px;
   background: url(images/gotop.gif) no-repeat;
   outline: none;
  }
 </style>


</head>

<body>
 <!-- 返回頂部小火箭 -->
 <div class="actGotop"><a href="javascript:;" rel="external nofollow" title="Top"></a></div>


 <script src="jquery-1.12.4.js"></script>
 <script>


  $(function () {
   //當(dāng)頁(yè)面超出1000px的時(shí)候,讓小火箭顯示,如果小于1000px,則隱藏
   $(window).scroll(function () {
    if ($(window).scrollTop() >= 1000) {
     $(".actGotop").stop().fadeIn(500);
    } else {
     $(".actGotop").stop().fadeOut(500);
    }
   })
  });

  //在外面注冊(cè)
  $(".actGotop").click(function () {
   $("html,body").stop().animate({ scrollTop: 0 }, 1000);
   //scrollTop為0
   // $(window).scrollTop(0);
  });
 </script>
</body>

</html>

以上就是本文的全部?jī)?nèi)容,希望對(duì)大家的學(xué)習(xí)有所幫助,也希望大家多多支持腳本之家。

相關(guān)文章

最新評(píng)論

奉新县| 商都县| 方城县| 阳朔县| 临湘市| 银川市| 沅陵县| 东宁县| 阳高县| 沧州市| 腾冲县| 赤壁市| 孝感市| 博爱县| 启东市| 西吉县| 体育| 大丰市| 柏乡县| 恩施市| 额敏县| 鄢陵县| 兰西县| 扶余县| 福建省| 都兰县| 荆门市| 郓城县| 无极县| 淅川县| 华容县| 双牌县| 沭阳县| 黄大仙区| 延寿县| 甘洛县| 福泉市| 陕西省| 乡城县| 绥中县| 买车|