jQuery實(shí)現(xiàn)小火箭返回頂部特效
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)擊小火箭,返回到頁面頂部。
在外面出冊點(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);
}
})
});
//在外面注冊
$(".actGotop").click(function () {
$("html,body").stop().animate({ scrollTop: 0 }, 1000);
//scrollTop為0
// $(window).scrollTop(0);
});
</script>
</body>
</html>
以上就是本文的全部內(nèi)容,希望對大家的學(xué)習(xí)有所幫助,也希望大家多多支持腳本之家。
- js+JQuery返回頂部功能如何實(shí)現(xiàn)
- 用jQuery實(shí)現(xiàn)的智能隱藏、滑動(dòng)效果的返回頂部代碼
- 基于jquery的返回頂部效果(兼容IE6)
- JQuery 動(dòng)畫卷頁 返回頂部 動(dòng)畫特效(兼容Chrome)
- 仿新浪微博返回頂部的jquery實(shí)現(xiàn)代碼
- jQuery中頁面返回頂部的方法總結(jié)
- jquery小火箭返回頂部代碼分享
- jQuery實(shí)現(xiàn)返回頂部功能適合不支持js的瀏覽器
- jquery左邊浮動(dòng)到一定位置時(shí)顯示返回頂部按鈕
- 使用jQuery實(shí)現(xiàn)返回頂部
相關(guān)文章
jQuery EasyUI中DataGird動(dòng)態(tài)生成列的方法
EasyUI中使用DataGird顯示數(shù)據(jù)列表中,有時(shí)需要根據(jù)需要顯示不同的列,例如,在權(quán)限管理中,不同的用戶登錄后只能查看自己權(quán)限范圍內(nèi)的列表字段,這就需要DataGird動(dòng)態(tài)組合列,下面介紹EasyUI中DataGird動(dòng)態(tài)生成列的方法2016-04-04
jQuery.Validate表單驗(yàn)證插件的使用示例詳解
jQuery Validate 插件為表單提供了強(qiáng)大的驗(yàn)證功能,讓客戶端表單驗(yàn)證變得更簡單,同時(shí)提供了大量的定制選項(xiàng),滿足應(yīng)用程序各種需求。接下來通過本文給大家介紹jQuery.Validate表單驗(yàn)證插件的使用示例,一起看看吧2017-01-01
用jQuery實(shí)現(xiàn)檢測瀏覽器及版本的腳本代碼
2008-01-01
JQuery學(xué)習(xí)筆記 nt-child的使用
在使用JQuery的時(shí)候如果你想尋找某個(gè)容器(諸如div或者是table中的某些子元素),那么很容易就使用find方法。2011-01-01
Jquery數(shù)字上下滾動(dòng)動(dòng)態(tài)切換插件
有時(shí)我們需要?jiǎng)討B(tài)的展示訪問次數(shù)、下載次數(shù)等效果,我們可以借助jQuery結(jié)合后臺php實(shí)現(xiàn)一個(gè)滾動(dòng)的數(shù)字展示效果。2015-08-08

