国产探花免费观看_亚洲丰满少妇自慰呻吟_97日韩有码在线_资源在线日韩欧美_一区二区精品毛片,辰东完美世界有声小说,欢乐颂第一季,yy玄幻小说排行榜完本

首頁 > 語言 > JavaScript > 正文

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

2024-05-06 15:44:03
字體:
供稿:網(wǎng)友

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

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

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

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

//當(dāng)頁面超出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)擊小火箭,返回到頁面頂部。

在外面出冊(cè)點(diǎn)擊事件,獲取頁面,html或者body, 返回用animate動(dòng)畫函數(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)頁面超出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í)有所幫助,也希望大家多多支持錯(cuò)新站長(zhǎng)站。

發(fā)表評(píng)論 共有條評(píng)論
用戶名: 密碼:
驗(yàn)證碼: 匿名發(fā)表

圖片精選

主站蜘蛛池模板: 瓦房店市| 九台市| 湘潭市| 大竹县| 当雄县| 银川市| 连南| 万州区| 南江县| 红桥区| 渭南市| 娄底市| 汾西县| 苍溪县| 泾阳县| 五华县| 通化市| 花莲县| 阜阳市| 都昌县| 孝昌县| 兴山县| 南康市| 从化市| 中方县| 永宁县| 临江市| 光山县| 永年县| 吉水县| 古田县| 遵义市| 无为县| 都昌县| 吴桥县| 裕民县| 天门市| 体育| 闽侯县| 定陶县| 洛浦县|