Is there a way to fix a position on the x-axis only? So when a user scrolls up, the div tag will scroll up with it, but not side to side?
相关问题
- Adding a timeout to a render function in ReactJS
-
Why does the box-shadow property not apply to a
- Add animation to jQuery function Interval
- jQuery hover to slide?
- Issue with star rating css
I just added position:absolute and that solved my problem.
Thanks
Sounds like you need to use position:fixed and then set the the top position to a percentage and the and either the left or the right position to a fixed unit.
Starx's solution was extremely helpful to me. But I had some problems when I tried to implement a vertical scrolling sidebar with it. Here was my initial code, based on what Starx wrote:
It's slightly different from Starx's solution, because I think his code is designed to allow a menu to float horizontally instead of vertically. But that's just an aside. The problem I had with the above code is that in a lot of browsers, or depending on the resource load of the computer, the menu movements would be choppy, whereas the initial css solution was nice and smooth. I attribute this to browsers being slower at firing javascript events than at implementing css.
My alternate solution to this choppiness problem is set the frame to fixed instead of absolute, then cancel out the horizontal movements using starx's method.
You might say all I'm doing is trading vertical scrolling choppiness for horizontal scrolling choppiness. But the thing is, 99% of scrolling is vertical, and it's much more annoying when that is choppy than when horizontal scrolling is.
Here's my related post on this matter, if I haven't already exhausted everyone's patience: Fixing a menu in one direction in jquery
Now that mobile is over 70% from the internet market you can create something smart and responsive to do that.
You can create this very easy with only css, use a overflow-x:scroll for a container and a overflow-y:scroll for another container. You can easily position the container elements with width:100vw and height:100vh.
Middle click on the example to test it. Works best on mobile because you dont see the scroll bars.
I realize this thread is mighty old but it helped me come up with a solution for my project.
In my case I had a header that I wanted to never be less than 1000px wide, header always on top, with content that could go unlimited right.
This also should handle when your browser is less than your headers min-width