Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 9090427
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 16, 20262026-06-16T22:22:10+00:00 2026-06-16T22:22:10+00:00

I have the following jQuery snippet $(‘html, body’).animate({ scrollTop: 178 }, 2000); I have

  • 0

I have the following jQuery snippet

$('html, body').animate({
    scrollTop: 178
}, 2000);

I have some pagination buttons at the bottom of the page, that trigger a javascript function when they are clicked. In this JS function, the above snippet is called.

This works fine to scroll the page back to the top just above the menu, but first of all the page seems to jump down to the very bottom abruptly (unless you are already at the very bottom) before scrolling up like it should?

I am tearing my hair out trying to figure this behaviour out.

I’m not sure how else to explain it apart from giving a link to the site: http://tinyurl.com/apdloyl

Go to the bottom of the page once the results have loaded, scroll up slightly, then click the next page button. And the weirdness happens as the page jumps down before scrolling back up.

Thanks for any help.

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-16T22:22:11+00:00Added an answer on June 16, 2026 at 10:22 pm

    So my solution was as follows

    I had a container div, #main, which had a height of ‘auto’ set in CSS.

    When my pagination button was pressed, the contents of this div were wiped and replaced with new content via ajax.

    When the contents were removed, the browser window shrunk and as a result you were always bumped to the bottom of the page.

    My fix was to immediately grab the height of the div, set it to it’s current height in fixed format, do the scroll to the top, and then once the scrollback was complete reset the div’s height to auto.

    Something like:

    /* First we have to fix the height of the #main element to prevent a nasty looking jerk                      when the ajax content dissapears */
    var height = $('#main').height();
    $('#main').height(height);
    
    /* Then we can scroll to the top */
    $('html, body').animate({
    scrollTop: 178
    }, 2000, function() {
    
        /* Then reset height to auto */
        $('#main').css('height','auto');
    
    });
    

    There are probably other more elegant ways of doing it but this works for me

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have the following snippet to scroll my form to the first error: $('html,body').stop().delay(500).animate({scrollTop:
I have following code (html,js,jquery) snippet ( http://jsfiddle.net/MUScJ/2/ ): <script type=text/javascript> function someFunc(){ html
I have the following html snippet: <div id=contentX><h1>MyHeading1</h1></div> I could select with jQuery snippet
I have the following snippet of code that loops through the jQuery animate function
I have the following snippet JQuery inside an HTML file: $.getJSON(/events/, function (data) {
I have following code snippet in jquery.In which,I want to animate each element of
I have the following simple jquery snippet $(document).ready(function () { $.ajax({ url:myjson.json, dataType: 'json',
I have the following snippet of code (I'm using jQuery 1.4.2): $.post('/Ads/GetAdStatsRow/', { 'ad_id':
In Ember.js's docs , they have a jQuery code snippet with the following syntax:
I have the following jquery code: $(document).ready(function() { $(body[class*=page-calendar-practices] #content-header h1#title).after(<div id='athletics_practice-schedule'><div id='inner-title'><a href='www.example.com'

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.