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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 18, 20262026-06-18T01:01:50+00:00 2026-06-18T01:01:50+00:00

I’ve a function that scrolls my Index page to a specific anchor tag and

  • 0

I’ve a function that scrolls my Index page to a specific anchor tag and changes the background image. The problem I have right now is that I need to use the links in my Menu page to move to the anchors in my Index page and change that background image. My Menu Page appears at the top of my index page.

The Javascript I have for scrolling inside my Index page is:

    $('-Button-to-scroll-is-clicked').click(function () {
        clearInterval(ID);
        $('html, body').animate({
            scrollTop: $('-Anchor').position().top
        },
        3000);
        var IntID = setInterval(changeImg, 1500);
        function changeImgHome() {
            $('.imagemhome').css('background', 'url(-New-Image.jpg) top center no-repeat fixed');
        };
        ID = IntID;
        return false;
    });

The Javascript that I have for scrolling my index page from my Menu page is:

     $('-Button-In-Menu-Page').click(function () {
         $('html, body').animate({
             scrollTop: $('-Anchor-In-Index-Page').position().top
         },
         3000);
         return false;
     });

As I’ve said, I need to check in my Index page the position I’m at after scrolling (using the window.scroll function) so I can change the background image appropriately.

  • 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-18T01:01:51+00:00Added an answer on June 18, 2026 at 1:01 am

    Well, first, position gathers the position of the element. By default, elements are placed inline and have a static position and no position coordinantes, so using .position().top will fail to yield the page position unless you’ve placed all of these things in absolutely.

    That’s not a problem though, because we have .offset. Offset tells you the x and y positions of the target relative to the document, so we’ll use that.

    Now our functions should look like this

    window.onready = function(){
        $(-Button-to-scroll).on('click',function(){
           var itemPos = $('target').offset().top;
           $('body,html').animate({scrollTop:itemPos},3000);
           $('.imagemhome').css('background', 'url(-New-Image.jpg) top center no-repeat fixed');
        }
    }
    

    EDIT: for your scrolling. This isn’t the most efficient way of doing it since it will basically keep rewriting your background image every time the user scrolls.

    $('html').on('scroll',function(){
        var top = $(this).offset().top
        if ((top >= 200)||(top <= 300)){
            $('.imagemhome').css('background', 'url(-New-Image.jpg) top center no-repeat fixed');
        }
    });
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have a string like this: La Torre Eiffel paragonata all&#8217;Everest What PHP function
That's pretty much it. I'm using Nokogiri to scrape a web page what has
this is what i have right now Drawing an RSS feed into the php,
I have a small JavaScript validation script that validates inputs based on Regex. I
I have a French site that I want to parse, but am running into
I'm parsing an RSS feed that has an &#8217; in it. SimpleXML turns this
I need a function that will clean a strings' special characters. I do NOT
I have been unable to fix a problem with Java Unicode and encoding. The
I have an MVC Razor view @{ ViewBag.Title = Index; var c = (char)146;
I have a .ini file as follows: [playlist] numberofentries=2 File1=http://87.230.82.17:80 Title1=(#1 - 365/1400) Example

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.