How do I make a menu like Wordpress that is vertical, fixed and has its own scrolling that is limited to its ends:
Inwordpressthedivoftheelementgetsa"position: fixed" when it reaches the end and the beginning of the menu to stop interacting with the scrolling, and when scrolling it defide "position: absolute" and "top: NumeroQueNaoConsigoDazer".
I was trying to do with javascript but it's impossible:
$(window).scroll(function(event) {
element = $('#sidebar_main');
p_current = $(this).scrollTop();
h_nav = element.height();
h_screen = $(window).height();
if(h_nav > h_screen){//se maior que a tela
h = (h_nav - h_screen)+40;
if(p_current > last_scroll){//se desce
if(p_current>=h){//se já chegou no fim
element.css({
'position': 'fixed',
'bottom': '0',
'top': 'auto'
});
}else{
if(element.css('top') == 'auto'){
element.css('top', 0);
}
element.css({
'top': '+=1px',
'position': 'absolute',
'bottom': 'auto'
});
}
}else{//se sobe
if(p_current<=0){//se já chegou no começo
element.css({
'top': '0',
'bottom': 'auto'
});
}else{
//if(element.offset().top <= h || element.css('top') == 'auto'){
if(element.css('top') == 'auto'){
element.css('top', element.offset().top);
}
element.css({
'top': '-=1px',
'position': 'absolute',
'bottom': 'auto'
});
}
//}
}
last_scroll = p_current;
}
});