[英]Position Fixed and Backface Visibility
I have three sectioning areas and within these I have a header element and a child item that is position fixed. 我有三个分区,其中有一个header元素和一个位置固定的子项。
As the user scrolls I want the next section to go over the previous section including its fixed child. 当用户滚动时,我希望下一部分遍历上一部分,包括其固定子级。
I have this working in Chrome by using backface visibility: 我可以通过使用背面可见性在Chrome中进行此操作:
-webkit-backface-visibility: hidden;
-moz-backface-visibility: hidden;
-ms-backface-visibility: hidden;
backface-visibility: hidden;
But in FF, the fixed items are no longer fixed. 但是在FF中,固定项目不再固定。 Take a look at the my jsfiddle http://jsfiddle.net/7KjXm/5/
看看我的jsfiddle http://jsfiddle.net/7KjXm/5/
Is this expected behaviour? 这是预期的行为吗? Is there a cross browser solution?
是否有跨浏览器解决方案? Or is JS the way to go?
还是JS要走?
Thanks.... 谢谢....
I managed to solve the effect you were looking for. 我设法解决了您想要的效果。 Unfortunately, it does not seem possible to do with only css ( yet ).
不幸的是,似乎仅靠css( yet )是不可能的。
Here is my solution that uses jquery and modified css of the original page. 这是我的解决方案,它使用jquery和原始页面的修改后的CSS。 I switched to numbers instead of colored elements and changed the sizes.
我改用数字而不是彩色元素,并更改了大小。
My javascript for fake floating elements (allows for them to be hidden when the view moves away): 我的JavaScript用于伪造的浮动元素(允许它们在视图移开时被隐藏):
$(function(){
elem = $('.fixeditem');
win = $(window);
wrap = $('<div>').css({
width: elem.width(),
height: elem.height()
});
elem.wrap(wrap);
win.scroll(function() {
elem.each(function(index, element){
element = $(element);
var offset = element.parent().offset().top;
element.css('top', win.scrollTop() + 40 - offset);
});
});
});
My custom css for this specific example: 我针对此特定示例的自定义CSS:
html, body{
height: 100%;
}
.item {
min-height:100%;
background-color: white;
position: relative;
z-index: 1;
overflow: hidden;
}
.header {
position: relative;
background-color: green;
padding: 5px;
z-index: 2;
}
.fixeditem {
position: relative;
top: 10%;
left: 50%;
z-index: 0;
}
Colored update of code: http://jsfiddle.net/8F2Zc/4/ 彩色代码更新: http : //jsfiddle.net/8F2Zc/4/
Hope this helps! 希望这可以帮助!
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.