Feature was originally introduced (as far as I can tell): #284413: Smooth scroll to top of page with AJAX page loading
Just looking at making a view option that allows it to be skipped, particularly in the case of something like http://drupal.org/project/views_load_more

For reference, javascript code that is triggering this behavior is found: http://drupalcode.org/project/views.git/blob/refs/heads/6.x-3.x:/js/ajax...

#2 views_scroll-top-optional-6x-1447332-2.patch10.33 KBwjaspers
None View


wjaspers’s picture

Found and modified all the code i think is necessary to accomplish this. Patch OTW.

wjaspers’s picture

Status: Active » Needs review
10.33 KB
None View

Here's a patch. This should cover all necessities, and falls back to the default scrolling behavior if the option hasn't been used before. Will not tag for Backport to 7.x until it has been reviewed.

wjaspers’s picture

Assigned: wjaspers » Unassigned
hachreak’s picture


Also I need to resolve this "bug"... XD

jcisio’s picture

Just a note that in D7 this behavior is already optional as it can be removed using hook_views_ajax_data_alter() to unset the scroll command (which was introduced in #1233334: Scroll to the top of a view after pager page load).

hachreak’s picture

Can we port this functionality for D6? :)

dawehner’s picture

Status: Needs review » Needs work
+++ b/includes/plugins.incundefined
@@ -28,6 +28,7 @@ function views_views_plugins() {
+        'will scroll top' => TRUE,

Are you sure it make sense to set this as definition for display plugins. Isn't it enough to have a setting?

In general the point of jcisio is also strong.

wjaspers’s picture

My original patch set that definition so the default value would continue to "scroll to top".
If this patch were rolled-in, it prevents existing views definitions from getting goofed up.

Manuel Garcia’s picture

Just for people looking to solve this right away:

 * Implement hook_views_ajax_data_alter().
function YOURMODULE_views_ajax_data_alter(&$commands, $view) {
  // Remove scroll to top behaviour from views ajax if using load_more pager.
  if ($view->display[$view->current_display]->display_options['pager']['type'] == 'load_more') {
    foreach ($commands as $key => $command) {
      if ($command['command'] == 'viewsScrollTop') {

Will remove the scroll to top behaviour for all views_load_more pager enabled views.

AdamGerthel’s picture

@Manuel just tried you solution (in template.php though) and it didn't work for me. I only have this issue in iOS (mobile safari) though

Edit: Solved. We were running the following script in behaviors (causing it to get triggered on all ajax requests):

  // Hide address bar
  if (navigator.platform == 'iPad' || navigator.platform == 'iPhone' || navigator.platform == 'iPod') {
wjaspers’s picture

@Manuel's solution shouldn't be placed in your template.php. It should exist in your own module for the site.

funature’s picture

patch of #9 used, but still scroll to top.

jcisio’s picture

#9 is for D7. The only patch to test is #2, but it's NW because of #7.

wjaspers’s picture

I set that so older views aren't inadvertently affected by this change.
By making the display plugin default "will_scroll_top" TRUE, they maintain their original behavior.

krisrobinson’s picture

Applied patch from #2 to views 6.x-3.0 (2012-Jan-04) and it worked fine, new setting available in views to enable/disable scroll to top. No errors so far, works good with views_load_more.