php定位导航系统,jQuery实现定位导航位置详解

本文主要为大家详细介绍了基于jQuery实现定位导航位置效果,具有一定的参考价值,感兴趣的小伙伴们可以参考一下,希望能帮助到大家。

当滚动条滚动到内容区域的时候,侧边导航条定位到屏幕,不再动,并且点击导航条跳转到内容所在的位置;

*{

padding: 0;

margin: 0;

}

.left{

float: left;

padding: 0 0 328px 0;

}

.left p{

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 p{

width: 100px;

height: 80px;

line-height: 80px;

text-align: center;

background: pink;

margin: 10px 0;

cursor: pointer;

}

.bottom{

overflow: hidden;

width: 100%;

position: relative;

}

Document

$(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 p').click(function(){

var i = $('.navp').index(this);

var x = $('.leftp').eq(i).offset().top;

$('html, body').animate({scrollTop:x+'px'},500);

})

相关推荐:

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值