none
JQuery scrolling in SharePoint RRS feed

  • Question

  • All,

    I am trying to have a page automatically scroll in SharePoint when a link is clicked. I am using jquery's animate function. This page uses a version of the V4 master page which I have customized. The jquery call I am using is this -

     $('html,body').animate({scrollTop:500},'slow');

    Using this code outside of SharePoint in an aspx page works fine. Once inside SharePoint, I get no scrolling. Can anyone help?

    Thanks

    Friday, September 7, 2012 1:21 PM

Answers

  • The SharePoint master page doesn't use the scolling on the "body" tag - in fact, it disables it and puts a scrollbar on a div tag with ID="s4-workspace". So you may need to replace your code with something like the following (untested):

    $('#s4-workspace').animate({scrollTop:500},'slow');


    Wade Hunter MCP/MCTS - WSS 3.0, MOSS 2007, SharePoint 2010


    Friday, September 7, 2012 1:40 PM

All replies

  • The SharePoint master page doesn't use the scolling on the "body" tag - in fact, it disables it and puts a scrollbar on a div tag with ID="s4-workspace". So you may need to replace your code with something like the following (untested):

    $('#s4-workspace').animate({scrollTop:500},'slow');


    Wade Hunter MCP/MCTS - WSS 3.0, MOSS 2007, SharePoint 2010


    Friday, September 7, 2012 1:40 PM
  • I struggled with this a bit until I found your page.  I replaced "html, body" with "#s4-workspace" and it worked.

    Thanks for sharing this tip. 

    Wednesday, November 20, 2013 2:31 PM
  • Thank pro, It works for me!
    Saturday, October 28, 2017 8:53 AM
  • Its working for share point user.

    If we try same with anonymous user whi accessing share point site then it fails.

    Any suggestions for this?

    I tried below code which worked for share point user but not for anonymous user.

            $('#s4-workspace').scrollTop(0);
            $(".login-now").trigger("click");
            $("[id*=txtName]").trigger('focus');

    Friday, November 24, 2017 1:24 PM
  •  $('#s4-workspace').scrollTop(0);
            $(".login-now").trigger("click");
            $("[id*=txtName]").trigger('focus');

    we need this fo sharepoint user for scrolling and below code is for anonymous user

    $('html, body').animate({ scroll

            $(".login-now").trigger("click");
            $("[id*=txtName]").trigger('focus');


    Tuesday, November 28, 2017 10:27 AM