Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to hover a Fixed element until it reaches some point

I've got a div which I need to be fixed to the bottom of the screen, until it reaches some point after scrolling and stop there and stay. If a user start scrolling back up - make it fixed again after passing that same point.

Any ideas on how this can be accomplished?

EDIT: (here's my current code which doesn't work)

$(window).scroll(function () {
    if ($(this).scrollTop() < $(document).height() - 81) {
        $('#bottom_pic').css('bottom', "0px");
    }
    else {
        $('#bottom_pic').css('bottom', "81px");
    }
});

CSS:

#bottom_pic 
{
    position: fixed;
    bottom: 0px;
}

Thanks!

like image 237
Roman Avatar asked Dec 07 '10 00:12

Roman


People also ask

How can you affect other elements when one element is hovered?

If you have two elements in your HTML and you want to :hover over one and target a style change in the other the two elements must be directly related--parents, children or siblings. This means that the two elements either must be one inside the other or must both be contained within the same larger element.

What is the difference between position absolute and fixed?

Whereas the position and dimensions of an element with position:absolute are relative to its containing block, the position and dimensions of an element with position:fixed are always relative to the initial containing block. This is normally the viewport: the browser window or the paper's page box.

How do you keep an element fixed in HTML?

To create a fixed top menu, use position:fixed and top:0 . Note that the fixed menu will overlay your other content. To fix this, add a margin-top (to the content) that is equal or larger than the height of your menu.

Which position will keep the element in the same place regardless of scrolling?

Fixed positioning This can be used to create a "floating" element that stays in the same position regardless of scrolling. In the example below, box "One" is fixed at 80 pixels from the top of the page and 10 pixels from the left. Even after scrolling, it remains in the same place relative to the viewport.


1 Answers

jQuery Waypoints is an excellent plugin to achieve things like this: Demo of fixed div after scrolling

like image 146
Björn Avatar answered Oct 09 '22 10:10

Björn