CSS Semi-fixed element?

I remember how I saw an example of this recently, but for life I can’t find the site.

It was a button or something similar, which sat in its place closer to the top of the screen, and then when you scroll down, it stays on the screen.

Now that I think about it, it must have worked on javascript, but it looked really natural.

Does anyone know a site with this functionality or information on how to do this?

EDIT
No, it was not easy position:fixedor constantly floating with javascript.

+3
source share
1 answer

durilai , : , ?

, , SO ( ), . " " , position:fixed, .

SO jQuery. , , :

var scrollerTopMargin = $("#scroll-container").offset().top;
$(window).scroll(function(){
    var c = $(window).scrollTop();
    var d = $("#scroll-container");
    if (c > scrollerTopMargin) {
        d.css({ position: "fixed", top: "0px"   });
    }
    else if (c <= scrollerTopMargin) 
    {
        d.css({ position: "relative", top: ""   });
    }
});
+2

Source: https://habr.com/ru/post/1737288/


All Articles