在我的项目中,我需要显示一个小图像,位于容器的可见部分的中心,相对于窗口,即
我已经成功实现了这一点,但现在我面临一个边缘情况,即当用户将页面滚动到“头部”或“底部”时,小图像会隐藏。 demo。
这实际上是正常的行为,但在这些边缘情况下,我希望图像粘在
我想要:
.loader
。即使用户滚动页面,图像也应该在.loader
的中心可见。我已经成功实现了这一点,但现在我面临一个边缘情况,即当用户将页面滚动到“头部”或“底部”时,小图像会隐藏。 demo。
这实际上是正常的行为,但在这些边缘情况下,我希望图像粘在
.loader
容器的顶部/底部。我想要:
- 始终将小图像保持在
.loader
容器的中心。(我已经实现了这个) - 当滚动到
.loader
容器的任何一端时,图像应该粘在那一端而不是隐藏在容器后面。
我希望使用纯CSS解决方案。我需要在IE9+、Chrome和Firefox浏览器中都能正常运行。
.header {
height: 600px;
width: 650px;
background-color: grey;
}
.left-side {
height: 300px;
width: 150px;
float: left;
background-color: red;
}
.loader {
background-image: url('http://i.imgur.com/U2njI.jpg');
margin-left: 150px;
height: 1500px;
width: 500px;
background-position: 345px center;
background-repeat: no-repeat;
background-attachment: fixed;
background-color: cornflowerblue;
}
.footer {
height: 600px;
width: 650px;
background-color: silver;
}
<div class="header"></div>
<div class="left-side"></div>
<div class="loader"></div>
<div class="footer"></div>