Javascript 不是那么简单的滚动
我不知道如何描述我所拥有的,所以我只是展示代码Javascript 不是那么简单的滚动,javascript,jquery,css,Javascript,Jquery,Css,我不知道如何描述我所拥有的,所以我只是展示代码 <div class="room-pos"> <div class="right-content nano-content"> <div id="right-fix"> </div> </div> <div class="left-content "> </div> </div> .room-pos{ pos
<div class="room-pos">
<div class="right-content nano-content">
<div id="right-fix">
</div>
</div>
<div class="left-content ">
</div>
</div>
.room-pos{
position: relative;
}
.fixed-c{
position:fixed;
}
.right-content{
background: #FFF none repeat scroll 0% 0%;
width: 45%;
position: absolute;
right: 0;
top:0;
bottom:0;
z-index:5;
border-left: 1px solid #F2F2F2;
}
.left-content{
width: 55%;
float: left;
}
$(window).scroll(function() {
if ($(this).scrollTop() >= $('#right-fix').height() - $(window).height() + 30) {
$('#right-fix').addClass( "fixed-c");
$("#right-fix").css("top", $(window).height() - $('#right-fix').height() );
} else if($(this).scrollTop() < $('#right-fix').height() - $(window).height() + 30) {
if ($('#right-fix').hasClass( "fixed-c")){
$('#right-fix').removeClass( "fixed-c");
}
}
.客房位置{
位置:相对位置;
}
.fixed-c{
位置:固定;
}
.正确的内容{
背景:#FFF无重复滚动0%0%;
宽度:45%;
位置:绝对位置;
右:0;
排名:0;
底部:0;
z指数:5;
左边框:1px实心#F2F2;
}
.左内容{
宽度:55%;
浮动:左;
}
$(窗口)。滚动(函数(){
if($(this).scrollTop()>=$('#right fix').height()-$(window.height()+30){
$('#right fix').addClass(“fixed-c”);
$(“#右定位”).css(“顶部”,$(窗口).height()-$(“#右定位”).height();
}else if($(this).scrollTop()<$('#right fix').height()-$(window.height()+30){
if($('#right fix').hasClass(“fixed-c”)){
$('#right fix').removeClass(“fixed-c”);
}
}
}))
我想要构建的内容:
因此,现在当您向下滚动一些scrollTop
参数时,右边的块变成fixed
和top:-some px
类似top:-832px
。我想改变这一点,这样当右块变为固定时,在开始滚动到页面顶部后,右块也开始滚动到顶部。
因此,当您滚动到底部时,右侧块也会滚动到底部并成为固定的,当您滚动到顶部时,右侧块也会滚动到顶部。所以我想我必须在css
parametr dynamic中更改top
,诸如此类的东西
我很难解释我的意思-我希望有人能理解
更新:新链接演示
更新2:添加我想要构建但算法中有缺陷的内容尝试找到一个具有你想要的效果的站点。提供指向示例的链接有助于其他人理解。我想查找,但我真的不知道哪个网站可以这样做。如果
$(“#右修复”)。height()
小于$(window)。height()
<代码>$(元素).css('top','-'+increment+'px')代码>是的,需要注册,但这不是我的问题,也是thx的问题that@willoller更新我的问题,它的工作与错误,但说明我想要什么