Scroll Calendar View so that it Centers (vertically) on page I've designed a calendar of events.  It uses a Next and Previous pager.  With the theme I am using, the top of the calendar displays part way down the screen when first viewed.  The user typically scrolls the screen using the mouse to bring the entire calendar into view.  This is problematic if the user needs to page to the next or prior month because he needs to once again use the mouse to position the entire calendar on the screen.

I'm not exactly clear on the best approach to resolve this.  I thought about looking into the theme code but wasn't sure if that's a good place to start.  I thought about trapping the display of each page of the calendar and trying to reposition (scroll) the page programmatically, but, that seemed like unnecessary code.

Can anyone advise me on a proper approach to solve this issue?  Ideally, I'd like the user to not have to scroll each page of the calendar when he uses the Next or Prior button.  It seems like there should be a way to ensure the entire calendar is visible.
One solution that comes to mind is to use hook_pager_link() to modify your view's pager links to include fragment/anchor that is in your view's header. This would work on the assumptions: 


You have custom unique text for previous/next pager links (e.g. "previous month"/"next month").
You placed an anchor link in your view header (e.g. &lt;a name="calendar"&gt;&lt;/a&gt;).


In your theme's template.php you could override like so:

function MYTHEME_pager_link($variables) {

  // If we are looking at pager links with our custom title 
  // use our modified theme_pager_link code:
  if (in_array($variables['text'], array('previous month', 'next month'))) {
    $text = $variables['text'];
    $page_new = $variables['page_new'];
    $element = $variables['element'];
    $parameters = $variables['parameters'];
    $attributes = $variables['attributes'];

    $page = isset($_GET['page']) ? $_GET['page'] : '';
    if ($new_page = implode(',', pager_load_array($page_new[$element], $element, explode(',', $page)))) {
      $parameters['page'] = $new_page;
    }

    $query = array();
    if (count($parameters)) {
      $query = drupal_get_query_parameters($parameters, array());
    }
    if ($query_pager = pager_get_query_parameters()) {
      $query = array_merge($query, $query_pager);
    }

    // Add our custom #calendar fragment
    $attributes['href'] = url($_GET['q'], array('query' =&gt; $query, 'fragment' =&gt; 'calendar'));
    return '&lt;a' . drupal_attributes($attributes) . '&gt;' . check_plain($text) . '&lt;/a&gt;';
  }
  else { // Otherwise fall back to core theme pager.
    return theme_pager_link($variables);
  }
}