Robert Granlund
asked on
Div position fixed vertically only
I have been asking and looking for a solution but none seem to work. So, I will ask the experts. I have a div on my website the contains a menu. I want the menu div to scroll vertically and stay in a fixed position. However, if you scroll horizontally I need to div to scroll as if it were position absolute.
This can not be accomplished with css. So, I need a jquery solution. Can anyone help?
This can not be accomplished with css. So, I need a jquery solution. Can anyone help?
What about the answer I gave you yesterday with Javascript?
https://www.experts-exchange.com/questions/27407230/CSS-fixed-positions.html
https://www.experts-exchange.com/questions/27407230/CSS-fixed-positions.html
<script type='text/javascript'>
window.onscroll = fixedYPos( 'fixed-element' );
function fixedYPos( elemId )
{
var elem = document.getElementById( elemId ),
xInit = elem.offsetLeft,
de = document.documentElement;
return function()
{
elem.style.left = xInit - ( window.pageXOffset || de.scrollLeft ) + 'px';
}
}
</script>
ASKER
@LZ
This is what I have. MY ID is text-87. What should the css for text-87 be?
This is what I have in the head:
This is what I have. MY ID is text-87. What should the css for text-87 be?
This is what I have in the head:
<script type='text/javascript'>
window.onscroll = fixedYPos( 'fixed-element' );
function fixedYPos(text-87)
{
var elem = document.getElementById(text-87),
xInit = elem.offsetLeft,
de = document.documentElement;
return function()
{
elem.style.left = xInit - ( window.pageXOffset || de.scrollLeft ) + 'px';
}
}
</script>
ASKER
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Actually it looks pretty good. It stays fixed and if I resize my browser the menu doesn't overlap the content
ASKER
@LZ If you are in FF and resize smaller and use your bottom scroll bar to scroll to the right, it goes under the other div.
For your CSS, try this:
If you keep it as absolute, yes the content will cover the menu, but the user will end up having to scroll back over to view the menu anyway.
#text-87 {
position: fixed;
z-index: 2147483647;
}
However, I don't know why your going to want this either as the menu is just going to mess up the content. If you keep it as absolute, yes the content will cover the menu, but the user will end up having to scroll back over to view the menu anyway.
ASKER
I'm trying to do this: http://demo.rickyh.co.uk/css-position-x-and-position-y/
EXAMPLE:
My position-x is absolute but position-y is fixed.
BUT, I can't use Mootools cause conflicts with Jquery
EXAMPLE:
My position-x is absolute but position-y is fixed.
BUT, I can't use Mootools cause conflicts with Jquery
http://jqueryfordesigners.com/fixed-floating-elements/
http://www.bennadel.com/blog/1810-Creating-A-Sometimes-Fixed-Position-Element-With-jQuery.htm
http://spyrestudios.com/demos/sliding-panel-fixed/