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 7400801
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 29, 20262026-05-29T04:18:15+00:00 2026-05-29T04:18:15+00:00

Hi just a quick doubt that’s driving me mad. I’m trying to automaticly scroll

  • 0

Hi just a quick doubt that’s driving me mad.

I’m trying to automaticly scroll down to an button when this button is clicked.

I’ve got the y-index value of my button saved on a variable called scrollIndex (thanks to the offset() method).

And now I’m trying to scroll down my window with this:

var scrollIndex = $('#tourbutton').offset();
$("body").animate({scrollTop:(scrollIndex.top)},500,"linear");

I’ve actually tried a lot of things but nothing seems to work and I supose it’s because I’m making a wrong use of the scrollTop method()..

Any help ? Thank you!

My full code:

window.onload = initAll; 

function initAll() { 
    changeStyle(); 
    $('#tourbutton').click = hello(); 
} 

function hello() { 
    var scrollIndex = $('#tourbutton').offset(); 
    $("html, body").animate({scrollTop:(scrollIndex.top)},800,"swing"); 
    //var scrollIndex = $('#tourbutton').offset();     
    //$("window").scrollTo({top:scrollIndex},800); 
}

SOLVED! I just wrote everything inside click() like this:

function initAll() {
$('#tourbutton').click(function() {

var scrollIndex = $('#tourbutton').offset();
$("html, body").animate({scrollTop:(scrollIndex.top)},800,"swing");

//var scrollIndex = $('#tourbutton').offset();
//$("window").scrollTo({top:scrollIndex},800);
});

    changeStyle();
}

And everything works now except I don’t quite understand why… if somebody understands why I cannot link the click eventHandler to an external function I’ll be glad to know the answer.

Thanks to all!

  • 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-05-29T04:18:16+00:00Added an answer on May 29, 2026 at 4:18 am

    Are you testing in Chrome? I ran into another SO question at some point where if you specified a body height of 100% in Chrome then setting scroll position didn’t work. You had to either put the body of your site in a scrollable div or not specify 100% height.

    Try this:

    var scrollIndex = $('#tourbutton').offset();
    $("html, body").animate({scrollTop:(scrollIndex.top)},500,"linear");
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Just a quick question that no doubt someone out there will know the answer
Just a quick question, I'm getting the idea that you don't. Why is this,
Just a quick regex question...hopefully I have a string that looks something like this:
Just a quick one. I am trying to work it the next element that
Just a quick question about best practice in MVC development. Let's say that I've
Just a quick and no doubt easy question. I'm pretty new to PHP and
Just a quick question. I understand that Singleton patterns can be extended and that
Just a quick question. I have an NSArray that is generated in my applicationDidFinishLaunching
Just a quick one, Is there anyway to shorthand this? It's basically determining the
Just a quick simple question, this css code will not work in ie8 for

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.