jQuery實(shí)現(xiàn)回到頂部效果
本文實(shí)例為大家分享了jQuery實(shí)現(xiàn)回到頂部效果的具體代碼,供大家參考,具體內(nèi)容如下
動(dòng)畫:通過點(diǎn)擊側(cè)欄導(dǎo)航,頁面到達(dá)相應(yīng)的位置
jQuery方法:show(), hide(), animate()
動(dòng)畫效果:

代碼:
<!DOCTYPE html>
<head>
<meta charset="UTF-8">
<title>回到頂部</title>
<script src="D:\jQuery/jquery-3.3.1.js"></script>
<style>
body, div, ul, li{
margin: 0;
padding: 0;
list-style: none;
}
#container{
margin: 10px;
}
#header{
width: 100%;
height:200px;
border: 2px solid #000;
}
#contant ul li{
width: 100%;
height:600px;
border: 2px solid #000;
}
#footer{
width: 100%;
height:200px;
border: 2px solid #000;
}
#scroll{
position: fixed;
right: 50px;
top: 300px;
width: 80px;
background: orange;
opacity: 0.5
}
#scroll ul{
list-style:none;
}
#scroll ul li{
width: 100%;
height: 45px;
line-height:45px;
text-align: center;
}
</style>
</head>
<body>
<div id="container">
<div id="header">頭部</div>
<div id="contant">
<ul>
<li>圖書</li>
<li>服裝</li>
<li>電子</li>
<li>寵物</li>
</ul>
</div>
<div id="footer">底部</div>
<div id="scroll">
<ul>
<li>圖書</li>
<li>服裝</li>
<li>電子</li>
<li>寵物</li>
<li>回到頂部</li>
</ul>
</div>
</div>
<script type="text/javascript">
$(document).ready(function () {
//當(dāng)鼠標(biāo)進(jìn)入側(cè)邊導(dǎo)航欄時(shí)改變側(cè)欄樣式
$("#scroll").mouseenter(function(){
$(this).css( "opacity",1 );
});
$("#scroll").mouseleave(function(){
$(this).css("opacity",0.5);
})
$("#scroll ul li").mouseover(function(){
$(this).css( {
"color":"red",
"cursor":"pointer"
});
});
$("#scroll ul li").mouseout(function(){
$(this).css("color","black");
})
//點(diǎn)擊側(cè)欄導(dǎo)航,頁面到達(dá)相應(yīng)位置
$("#scroll ul li").click(function () {
switch($(this).index()){
case 4:
// $(window).scrollTop(0);
$(document.body).animate({"scrollTop":0},1000);
$(document.documentElement).animate({"scrollTop":0},1000);
break;
case 0:
$(document.body).animate({"scrollTop":200},1000);
$(document.documentElement).animate({"scrollTop":200},1000);
break;
case 1:
$(document.body).animate({"scrollTop":800},1000);
$(document.documentElement).animate({"scrollTop":800},1000);
break;
case 2:
$(document.body).animate({"scrollTop":1400},1000);
$(document.documentElement).animate({"scrollTop":1400},1000);
break;
case 3:
$(document.body).animate({"scrollTop":2000},1000);
$(document.documentElement).animate({"scrollTop":2000},1000);
break;
default:
break;
}
});
});
</script>
</body>
<html>
以上就是本文的全部內(nèi)容,希望對大家的學(xué)習(xí)有所幫助,也希望大家多多支持腳本之家。
- jQuery實(shí)現(xiàn)簡單的回到頂部totop功能示例
- 如何利用JQuery實(shí)現(xiàn)從底部回到頂部的功能
- jquery實(shí)現(xiàn)點(diǎn)擊頁面回到頂部
- jquery實(shí)現(xiàn)跳到底部,回到頂部效果的簡單實(shí)例(類似錨)
- jQuery回到頂部的代碼
- jQuery實(shí)現(xiàn)帶有動(dòng)畫效果的回到頂部和底部代碼
- jquery實(shí)現(xiàn)的動(dòng)態(tài)回到頂部特效代碼
- jQuery實(shí)現(xiàn)分章節(jié)錨點(diǎn)“回到頂部”動(dòng)畫特效代碼
- jquery網(wǎng)頁回到頂部效果(圖標(biāo)漸隱,自寫)
相關(guān)文章
jQuery實(shí)現(xiàn)簡潔的導(dǎo)航菜單效果
這篇文章主要介紹了jQuery實(shí)現(xiàn)簡潔的導(dǎo)航菜單效果,簡潔大方的導(dǎo)航菜單,需要的朋友可以參考下2015-11-11
jQuery插件實(shí)現(xiàn)控制網(wǎng)頁元素動(dòng)態(tài)居中顯示
這篇文章主要介紹了jQuery插件實(shí)現(xiàn)控制網(wǎng)頁元素動(dòng)態(tài)居中顯示,實(shí)例分析了jQuery插件的實(shí)現(xiàn)與元素動(dòng)態(tài)顯示的技巧,需要的朋友可以參考下2015-03-03
基于JQuery 滑動(dòng)與動(dòng)畫的說明介紹
本篇文章小編為大家介紹,基于JQuery 滑動(dòng)與動(dòng)畫的說明介紹。需要的朋友參考下2013-04-04
JQuery+EasyUI輕松實(shí)現(xiàn)步驟條效果
jQuery EasyUI 提供易于使用的組件,它使 Web 開發(fā)人員能快速地在流行的 jQuery 核心和 HTML5 上建立程序頁面。通過本文給大家介紹JQuery+EasyUI輕松實(shí)現(xiàn)步驟條效果,需要的朋友參考下2016-02-02
jquery中實(shí)現(xiàn)標(biāo)簽切換效果的代碼
現(xiàn)在比較流行jquery插件,所以既然用了jquery那么就要用好,也不用大量的寫代碼了。2011-03-03
jQuery 1.9.1源碼分析系列(十)事件系統(tǒng)之主動(dòng)觸發(fā)事件和模擬冒泡處理
這篇文章主要介紹了jQuery 1.9.1源碼分析系列(十)事件系統(tǒng)之主動(dòng)觸發(fā)事件和模擬冒泡處理的相關(guān)資料,需要的朋友可以參考下2015-11-11
jQuery利用cookie 實(shí)現(xiàn)本地收藏功能(不重復(fù)無需多次命名)
cookie 是存儲(chǔ)于訪問者計(jì)算機(jī)中的變量。這篇文章主要介紹了jQuery利用cookie 實(shí)現(xiàn)本地收藏功能不重復(fù)無需多次命名,需要的朋友可以參考下2019-11-11

