Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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.

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:

-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. Take a look at the my jsfiddle http://jsfiddle.net/7KjXm/5/

Is this expected behaviour? Is there a cross browser solution? Or is JS the way to go?

Thanks....

like image 511
jigglyT101 Avatar asked Feb 20 '14 07:02

jigglyT101


People also ask

What does Backface visibility mean?

The backface-visibility property defines whether or not the back face of an element should be visible when facing the user. The back face of an element is a mirror image of the front face being displayed. This property is useful when an element is rotated. It lets you choose if the user should see the back face or not.

What is Backface visibility in react native?

Answer : The backfaceVisibility prop is used to hide the back face of a Image or View component. When we rotate a image or View in Y-Direction manner like horizontally. Then when view flip 180 degree it does display its back face or back part.

What happens when an element is styled as follows Backface visibility hidden?

The back face is visible when turned towards the user. The back face is hidden, effectively making the element invisible when turned away from the user.


1 Answers

I managed to solve the effect you were looking for. Unfortunately, it does not seem possible to do with only css (yet).

Here is my solution that uses jquery and modified css of the original page. 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):

$(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:

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/

Hope this helps!

like image 103
Tyler Scott Avatar answered Oct 14 '22 11:10

Tyler Scott