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

  • Home
  • SEARCH
  • 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 8094373
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 5, 20262026-06-05T20:46:52+00:00 2026-06-05T20:46:52+00:00

I am trying write a script where when a user clicks on a link,

  • 0

I am trying write a script where when a user clicks on a link, the page will scroll down to a target minus 20px (ie – if my target is located at [0,100] the page will scroll to [0,80]. The reason for this 20px difference is because I have a banner positioned on a layer above my site of 20px height.

Currently, my approach is to scroll directly to my target, then subtract 20px from my current location. I am having problems determine where my current y position is though.

HTML:

<nav>
  <a href="#chapterA" class="link">ChapterA</a>
  <a href="#chapterB" class="link">ChapterB</a>
</nav>
...
<a name="chapterA">ChapterA</a>
<a name="chapterB">ChapterB</a>

jQuery:

$('.link').click(function() {
  var currentY = 0; //how to get current y position?
  window.scrollTo(0, currentY - 20);
});
  • 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-05T20:46:54+00:00Added an answer on June 5, 2026 at 8:46 pm

    try this:

    $('.link').click(function(e) {
      e.preventDefault()
      $(window).scrollTop($(window).scrollTop() - 20);
    });
    

    note that anchor links without href attribute are not valid.

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

Sidebar

Related Questions

I'm trying to write a script that will create a user in MediaWiki, so
I'm trying to write a bash script that wraps whatever the user wants to
I'm trying to write a script that will download files from an FTP server.
I am trying to write a script that I can give to user to
I am trying to write a PHP script that will create an HTML form
OK here goes, I am trying to write a script that, when a user
I'm trying to write a script that informs the user when someone has logged
I'm trying to write a shell script that, when run, will set some environment
I am trying to write a script that archives a user by setting the
I'm trying write a Ruby script that checks if user credentials are valid using

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.