Kri*_*isF 14 javascript css jquery html5
我在页面中间有一个固定的div.我有另一个div包含一个图像库.目前,图像按预期滚动"固定div"下方.但我想要的是一个效果,图像永远不会隐藏在固定的div下面.它们不会分散,而是会分裂,部分图像显示在下方,部分位于上方.基本上我打算将一个div(带图像库的那个)分成两部分,部分显示在固定div下方和上面部分.这是一些花哨的图形,以更好地说明我希望做的事情.
我很高兴使用所需的任何css/html/javascript组合.
可能吗?
Current Behavior Desired Behavior
|===================| |===================|
| ===== ===== | | ===== ===== |
| | | | | | | | | | | |
| | img | | img | | | | img | | img | |
| | 1 | | 2 | | | | 1 | | 2 | |
| ===== ===== | | ===== ===== |
|===================| |===================|
| fixed div | | fixed div |
|===================| |===================|
| | 3 | | 4 | | | ===== ===== |
| ===== ===== | | | | | | |
| ===== ===== | | | img | | img | |
| | | | | | | | 3 | | 4 | |
| | img | | img | | | ===== ===== |
|===================| |===================|
Run Code Online (Sandbox Code Playgroud)
滚动一下
|===================| |===================|
| | img | | img | | | | img | | img | |
| | 1 | | 2 | | | | 1 | | 2 | |
| ===== ===== | | ===== ===== |
| ===== ===== | | ===== ===== |
| | | | | | | | | | | |
|===================| |===================|
| fixed div | | fixed div |
|===================| |===================|
| ===== ===== | | | img | | img | |
| | | | | | | | 3 | | 4 | |
| | img | | img | | | ===== ===== |
| | 5 | | 6 | | | ===== ===== |
| ===== ===== | | | | | | |
|===================| |===================|
Run Code Online (Sandbox Code Playgroud)
滚动一点
|===================| |===================|
| ===== ===== | | ===== ===== |
| ===== ===== | | ===== ===== |
| | | | | | | | | | | |
| | img | | img | | | | img | | img | |
| | 3 | | 4 | | | | 3 | | 4 | |
|===================| |===================|
| fixed div | | fixed div |
|===================| |===================|
| | img | | img | | | ===== ===== |
| | 5 | | 6 | | | ===== ===== |
| ===== ===== | | | | | | |
| ===== ===== | | | img | | img | |
| | | | | | | | 5 | | 6 | |
|===================| |===================|
Run Code Online (Sandbox Code Playgroud)
在这里,我快速整理了html,css和jquery的组合,这对我在Chrome中起作用.
HTML:
<div id="toppart">
<div class="tiles">
<div class="tile">1</div>
<div class="tile">2</div>
<div class="tile">3</div>
<div class="tile">4</div>
<div class="tile">5</div>
<div class="tile">6</div>
</div>
</div>
<div id="strap">
<p>the fixed strap</p>
</div>
<div id="bottompart"></div>
Run Code Online (Sandbox Code Playgroud)
css的关键部分:
#strap {
position:absolute;
top:45%;
height: 10%;
background-color:blue;
}
#toppart, #bottompart {
background-color:#fff;
position:absolute;
height:45%;
overflow:auto;
}
#bottompart {
top:55%;
z-index:-1;
}
#bottompart div {
position:relative;
top:-100%;
}
Run Code Online (Sandbox Code Playgroud)
和JavaScript代码:
$(document).ready(function () {
//mirror contents
$('#bottompart').append($('#toppart').html());
//scroll bottom with top
$("#toppart").scroll(function(){
$("#bottompart").scrollTop($("#toppart").scrollTop());
});
//scroll top with bottom
$("#bottompart").scroll(function(){
$("#toppart").scrollTop($("#bottompart").scrollTop());
});
});
Run Code Online (Sandbox Code Playgroud)
希望你能得到这个想法;-)
这对于 CSS 来说是不可能的。我看到的唯一可行的实现是让顶部和底部 div 具有完全相同的内容,侦听它们的 onscroll 事件,然后将它们与另一个具有所需间隙的“同步”。不过,您可能需要对 iOS 设备进行一些降级,因为它们在滚动完成之前不会发送 onscroll 事件。