Vertical position locked

I need to fix the div / image 16 pixels from the top of the window ... The content needs to scroll, but the div / image cannot scroll ... My main problem is that it cannot be fixed with the position attribute, because I need to scroll it horizontally. and with the position: it is fixed that it is fixed both vertically and horizontally ...
I already tried overflow (overflow-y: hidden does not work) and cannot get any results ...
Can I say that div / image should block its vertical movement in this place? any ideas?

+4
source share
2 answers

If you are trying to lock the div vertically, but allow the image to scroll horizontally, as @Paulie_D suggests, you can try this script:

http://jsfiddle.net/bnu4rhop/

It depends on a position: fixedwith an accompanying javascript function that adjusts the leftcss value .

$(window).scroll(function (e) {
    $('#my_div').css({left: -$(window).scrollLeft()})
});
+2
source

Just a position: your div is absolute and when the user scrolls adjust the top value using javascript:

 $(window).scrollTop() + 16; 

If you want to center your div horizontally:

left: 50%;
margin-left: -(You div width / 2);
+1
source

All Articles