简体   繁体   English

固定位置和背面可见性

[英]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.

相关问题 背面能见度不适用于野生动物园 - backface visibility not working in safari CSS:图片而不是背面可见性=隐藏 - CSS : picture instead of backface-visibility = hidden Three.js是否具有等效的背面可见性? - Is there a backface-visibility equivalent for three.js? 背面可见性在IE11中无效 - backface visibility not working in IE11 在Google地图中的固定位置显示图片; 可见性取决于缩放级别 - Show an image in a fixed position in Google Maps; visibility depends on the zoom level CSS3属性“背面可见性”不适用于任何IE版本 - CSS3 property 'backface-visibility' not working with any IE versions IE11是否有“Backface-visibility:hidden”替代方案? - Is there a “Backface-visibility:hidden” alternative for IE11? 如何让使用背面可见性的图像在转换后不消失? - How do I get my image that uses backface-visibility to not disappear after transforming? Chrome中可能存在的错误 - 使用背面可见性时,视频控件仍然可见:隐藏在HTML5视频上 - Possible bug in Chrome - Video controls are still visible when using backface-visibility:hidden on HTML5 videos iOS:带有-webkit-backface-visibility的多个div:缩放时隐藏的崩溃浏览器 - iOS: Multiple divs with -webkit-backface-visibility:hidden crash browser when zooming
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM