Posts: 65
Location: san francisco, ca
|
Code:
$('select').focus(function(){
var center = $(window).height()/2;
var top = $(this).offset().top ;
if (top > center){
$(window).scrollTop(top-center);
}
});
The following function accurately centers my page on the vertical axis. Meaning, on a page with large amounts of select-lists, whichever one has focus, the page will be scrolled (centered vertically).
I've tried unsuccessfully to modify this function to do the same thing for the horizontal axis. Meaning: with many select-lists oriented horizontally in a side-scrolling container; whichever select-list has focus, the container would scroll (center horizontally)
Its a syntax issue on my part; i just cant find the way to modify this function (or create a derivative) that also performs the centering on the horizontal axis.
Thanks in advance...
|