cypher75
cypher75

Reputation: 2179

How can I set a div to position:fixed, when scrolling it to the browsers top?

I hope I can describe my problem:

I have a shopping basket div with price information below a header (logo, topnav) on my page. When scrolling down the page, I want the shopping basket div to stop scrolling (position:fixed), when it touches the upper end of the browser...

Does anyone have a keyword for what I'm looking for?

Thanks

Jan

Upvotes: 0

Views: 216

Answers (1)

Anarion
Anarion

Reputation: 1038

Let's imagine that you have jQuery and your shopping basket has class 'cart'

$(document).on('scroll', function(){
   if($(document).scrollTop() >= $('.cart').offset().top){
      // Add position:fixed styling (eg. with a specific class)
   } else {
      // Remove position:fixed styling
   }
});

Upvotes: 2

Related Questions