Warning: Undefined array key "action" in /home/bakers/html/entryreply.php on line 5

Warning: Undefined variable $output in /home/bakers/html/entryreply.php on line 50

Warning: Undefined array key "EntrySubject" in /home/bakers/html/entryreply.php on line 51

Warning: Undefined variable $logintext in /home/bakers/html/entryreply.php on line 97

Warning: Undefined variable $reply_name in /home/bakers/html/entryreply.php on line 103

Warning: Undefined variable $reply_email in /home/bakers/html/entryreply.php on line 104
Perturb.org - interesting technology related things from around the internet

jQuery: center the viewport on an element

If you have a page that's very long vertically (something that requires a scrollbar) and you want to center the viewport on a specific element do this:

var elem_top = $("#my_item").offset()['top'];
var viewport_height = $(window).height();

// Scroll to the middle of the viewport
var my_scroll = elem_top - (viewport_height / 2);
$(window).scrollTop(my_scroll);


Note: Replies will be formatted with PHP Markdown Extra syntax.

Name: Email (Not Required):
 
Logged IP: 3.227.235.216
To prevent spam please submit by clicking the kitten: