I have an element that is position:fixed and so scrolls with the page how i want it to however. when the user scrolls up I want the element to stop scrolling at a certain point, say when it is 250px from the top of the page, is this possible? Any help or advice would be helpful thanks!
I had a feeling that I would need to use jquery to do so. I tried getting the scrolling or location of the where the user is but got really confused, is there any jquery solutions?
Here's a quick jQuery plugin I just wrote that can do what you require:
See working example →
I adapted @mVchr's answer and inverted it to use for sticky ad positioning: if you need it absolutely positioned (scrolling) until the header junk is off screen but then need it to stay fixied/visible on screen after that:
CSS:
I loved @james answer but I was looking for its inverse i.e. stop fixed position right before footer, here is what I came up with
So now the fixed element would stop right before footer. and will not overlap with it.
A possible CSS ONLY solution can be achived with
position: sticky;
The browser support is actually really good: https://caniuse.com/#search=position%3A%20sticky
here is an example: https://jsfiddle.net/0vcoa43L/7/
Here is a complete jquery plugin that solves this problem:
https://github.com/bigspotteddog/ScrollToFixed
The description of this plugin is as follows:
This plugin is used to fix elements to the top of the page, if the element would have scrolled out of view, vertically; however, it does allow the element to continue to move left or right with the horizontal scroll.
Given an option marginTop, the element will stop moving vertically upward once the vertical scroll has reached the target position; but, the element will still move horizontally as the page is scrolled left or right. Once the page has been scrolled back down past the target position, the element will be restored to its original position on the page.
This plugin has been tested in Firefox 3/4, Google Chrome 10/11, Safari 5, and Internet Explorer 8/9.
Usage for your particular case:
my solution