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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 11, 20262026-06-11T07:30:38+00:00 2026-06-11T07:30:38+00:00

As the title says, I think this code can be simplified in less lines.

  • 0

As the title says, I think this code can be simplified in less lines. Could someone help me with this?

    $('a[href=#over]').click(function(){
    $('html, body').animate({
        scrollTop: $("#over").offset().top - 100
    }, 2000);
});

$('a[href=#diensten]').click(function(){
    $('html, body').animate({
        scrollTop: $("#diensten").offset().top - 100
    }, 2000);
});

$('a[href=#portfolio]').click(function(){
    $('html, body').animate({
        scrollTop: $("#portfolio").offset().top - 100
    }, 2000);
});

$('a[href=#contact]').click(function(){
  $("html, body").animate({ scrollTop: $(document).height() }, 2000);
});

$('a[href=#top]').click(function(){
    $('html, body').animate({scrollTop:0}, 2000);
    return false;
});

I was thinking myself off an if/elseif statement, but im kinda stuck in there. So could you please have an look?

  • 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-11T07:30:40+00:00Added an answer on June 11, 2026 at 7:30 am

    You can use the href attribute of anchors for selecting the element by IDs.

    $('a').click(function(){
        var id = this.href;
        $('html, body').animate({
            scrollTop: $(id).offset().top - 100
        }, 2000);
    });
    

    $('a').click(function(e) {
        e.preventDefault();
        var id = this.href;
        var scroll = '';
        if (id === '#contact') {
           scroll =  $(document).height();
        } else if (id === '#top') {
           scroll = 0;
        } else {
           scroll = $(id).offset().top - 100;
        }
        $('html, body').animate({
               scrollTop: scroll
        }, 2000)
    });
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I think title says what I need. I know we can use asd function
Exactly as the title says, I think I was looking at c# code when
As the title says I am trying to get help simplifing my code. I
The title says enough I think. I have a full quality BufferedImage and I
I think the title says most of my problem. I am new to C
OK, I don't think the title says it right... but here goes: I have
I have written a code which does the thing as the title says. The
Title says all. Sample code: ArrayList<HashMap<String, Object>> data = new ArrayList<HashMap<String, Object>>(); HashMap<String, Object>
As title says, i know that new throws an exception which can be caught,
As the title says I want to transfer data, in this case the information

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.