基于jQuery實(shí)現(xiàn)定位導(dǎo)航位置效果
本文實(shí)例為大家分享了Android九宮格圖片展示的具體代碼,供大家參考,具體內(nèi)容如下
當(dāng)滾動(dòng)條滾動(dòng)到內(nèi)容區(qū)域的時(shí)候,側(cè)邊導(dǎo)航條定位到屏幕,不再動(dòng),并且點(diǎn)擊導(dǎo)航條跳轉(zhuǎn)到內(nèi)容所在的位置;
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<meta http-equiv="X-UA-Compatible" content="ie=edge">
<style>
*{
padding: 0;
margin: 0;
}
.left{
float: left;
padding: 0 0 328px 0;
}
.left div{
width: 800px;
height: 300px;
line-height: 300px;
text-align: center;
font-size: 30px;
background: gray;
margin: 10px 0;
}
.nav{
position: absolute;
right:20px;
top: 20px;
}
.nav div{
width: 100px;
height: 80px;
line-height: 80px;
text-align: center;
background: pink;
margin: 10px 0;
cursor: pointer;
}
.bottom{
overflow: hidden;
width: 100%;
position: relative;
}
</style>
<title>Document</title>
</head>
<body>
<img style="width:100%" src="o_1bsmo1kpn1hp61bm0176i1bk618uo9.jpg" alt="">
<div class="bottom">
<div class="left">
<div class="one leftDiv" id="one">
一
</div>
<div class="conOne leftDiv" id="two">
二
</div>
<div class="leftDiv" id="three ">
三
</div>
<div class="leftDiv" id="four">
四
</div>
</div>
<div class="nav">
<div class="one navDiv">one</div>
<div class="two navDiv">two</div>
<div class="three navDiv">three</div>
<div class="four navDiv">four</div>
</div>
</div>
<script src="jquery.js"></script>
<script>
$(window).scroll(function(e){
console.log($(window).scrollTop());
if ($(window).scrollTop() >$('#one').offset().top) {
$('.nav').css({'position':'fixed'});
console.log('ss');
} else{
$('.nav').css({'position':'absolute'});
}
})
$('.nav div').click(function(){
var i = $('.navDiv').index(this);
var x = $('.leftDiv').eq(i).offset().top;
$('html, body').animate({scrollTop:x+'px'},500);
})
</script>
</body>
</html>
以上就是本文的全部?jī)?nèi)容,希望對(duì)大家的學(xué)習(xí)有所幫助,也希望大家多多支持腳本之家。
相關(guān)文章
jQuery+css實(shí)現(xiàn)非常漂亮的水平導(dǎo)航菜單效果
這篇文章主要介紹了jQuery+css實(shí)現(xiàn)非常漂亮的水平導(dǎo)航菜單效果,通過(guò)each方法遍歷元素再使用removeClass與addClass變換頁(yè)面元素樣式實(shí)現(xiàn)導(dǎo)航菜單的切換效果,需要的朋友可以參考下2016-07-07
淺談DOCTYPE對(duì)$(window).height()取值的影響
下面小編就為大家?guī)?lái)一篇淺談DOCTYPE對(duì)$(window).height()取值的影響。小編覺(jué)得挺不錯(cuò)的,現(xiàn)在就分享給大家,也給大家做個(gè)參考。一起跟隨小編過(guò)來(lái)看看吧2016-07-07
基于?jquery-cxselect?實(shí)現(xiàn)下拉聯(lián)動(dòng)效果功能實(shí)現(xiàn)
這篇文章主要介紹了基于?jquery-cxselect?實(shí)現(xiàn)下拉聯(lián)動(dòng)效果,下拉聯(lián)動(dòng)是基于query的一款聯(lián)動(dòng)下拉菜單插件 jquery-cxselect實(shí)現(xiàn),本文通過(guò)實(shí)例代碼給大家介紹的非常詳細(xì),需要的朋友可以參考下2023-02-02
JQuery validate 驗(yàn)證一個(gè)單獨(dú)的表單元素實(shí)例
下面小編就為大家?guī)?lái)一篇JQuery validate 驗(yàn)證一個(gè)單獨(dú)的表單元素實(shí)例。小編覺(jué)得挺不錯(cuò)的,現(xiàn)在就分享給大家,也給大家做個(gè)參考。一起跟隨小編過(guò)來(lái)看看吧2017-02-02
jquery實(shí)現(xiàn)圖片隨機(jī)排列的方法
這篇文章主要介紹了jquery實(shí)現(xiàn)圖片隨機(jī)排列的方法,涉及jQuery操作圖片的相關(guān)技巧,非常具有實(shí)用價(jià)值,需要的朋友可以參考下2015-05-05
jquery實(shí)現(xiàn)二級(jí)導(dǎo)航下拉菜單效果
這篇文章主要介紹了jquery實(shí)現(xiàn)二級(jí)導(dǎo)航下拉菜單效果,具有一定參考借鑒價(jià)值,需要的朋友可以參考下2015-12-12

