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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 12, 20262026-06-12T10:46:06+00:00 2026-06-12T10:46:06+00:00

I am trying to make an scroll animation when someone access to an anchor

  • 0

I am trying to make an scroll animation when someone access to an anchor link, like this:

www.miweb.com/section/#anchorLink

And I am doing it with this code, but there’s something wrong in it because i can not execute anything else after it (alert(“the end”) in this case) in case a user access to the URL with no anchor ID.

$('html, body').animate({
    scrollTop:$('[name="'+window.location.hash.replace("#", "")+'"]').offset().top
}, 500);

alert("the end");

If the user access from a URL with anchor ID, it will be executed.

How can i do to execute code after this function in any case?

Thanks.

  • 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-12T10:46:07+00:00Added an answer on June 12, 2026 at 10:46 am

    If what you want is to execute code after the animation, do like this:

    $('html, body').animate({
        scrollTop:$('[name="'+window.location.hash.replace("#", "")+'"]').offset().top
    }, 500, function() {
        alert("the end");
    });
    

    Update:
    After OP’s comments, I think you are having javascript error accessing top property when offset() is null (which is the case when there’s no anchor), so you guard against accesing that possible null reference, like so:

    dest = $('[name="'+window.location.hash.replace("#", "")+'"]').offset();
    dtop = dest != null ? dest.top : null;
    $('html, body').animate({
        scrollTop: dtop
    }, 500);
    
    alert("the end");​
    

    Now the alert() should print just fine.

    You could easily spot similar errors like this in future if you look at the browser javascript console, I just did so and saw the error about the null reference.

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

Sidebar

Related Questions

I am experimenting with this: http://dev.sencha.com/deploy/ext-4.0.0/examples/grid/infinite-scroll.html I'm trying to make it possible for the
I am trying to make this infinite scroll script work the way i want.
I'm trying to make my page slides scroll when I click on a link
I am trying to make feature like on the first page of foursquare.com (feed
I'm trying to make a scroll panel that has relative size parameters. But the
I am trying to make Custom RelativeLayout which can scale and scroll. Right now
I am trying to make a Javascript that loops infinitly. function scroll(num) { $(.
I'm trying to make a twitter like system that scrolls through info slowly and
Trying to make this jQuery filter that uses .find case-insensitive. For example, when the
I'm trying to make a slot machine animation where the reels spin. to do

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.