How can I make a div stick to the top of the screen once it's been scrolled to?

后端 未结 21 1451
Happy的楠姐
Happy的楠姐 2020-11-22 07:12

I would like to create a div, that is situated beneath a block of content but that once the page has been scrolled enough to contact its top boundary, becomes fixed in place

21条回答
  •  抹茶落季
    2020-11-22 08:05

    The info provided to answer this other question may be of help to you, Evan:

    Check if element is visible after scrolling

    You basically want to modify the style of the element to set it to fixed only after having verified that the document.body.scrollTop value is equal to or greater than the top of your element.

提交回复
热议问题