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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 26, 20262026-05-26T00:38:12+00:00 2026-05-26T00:38:12+00:00

I am completely new to javascript, but I want to learn it rather than

  • 0

I am completely new to javascript, but I want to learn it rather than jQuery to get some fundamental knowledge. The function I want to create should animate an arrow to turn upwards when it passes 50% of the page. In addition to this, the function that it calls when upside down should change.

So: upArrow onClick(scrollUp)
downArrow onClick(scrollDown)

I’m sure I sound stupid, but maybe someone can understand what I’m trying to explain.

  • 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-26T00:38:12+00:00Added an answer on May 26, 2026 at 12:38 am

    You can either write the imageelement.src property to point to a different arrow, or, for extra smoothness, use a CSS sprite containing both arrows and write element.style.backgroundPosition to change the displayed image without having to load a new image.

    You can assign a new function to imageelement.onclick to change what happens when you click on it, but usually it is simpler to have one click-function that decides what to do based on state.

    eg:

    <div id="arrow" class="arrow-down"></div>
    
    
    #arrow {
        position: fixed; top: 0; left: 0; z-index: 10;
        width: 32px; height: 32px;
        background-image: url(/img/arrow.png);
    }
    .arrow-down {
        background-position: 0 0;
    }
    .arrow-up {
        background-position: 0 -32px;
    }
    
    
    var arrow= document.getElementById('arrow');
    
    window.onscroll=window.onresize= function() {
        arrow.className= isHalfwayDown()? 'arrow-up' : 'arrow-down';
    };
    arrow.onclick= function() {
        var h= document.documentElement.scrollHeight;
        scrollTo(0, isHalfwayDown()? 0 : h);
        window.onscroll();
    };
    
    function isHalfwayDown() {
        var y= document.documentElement.scrollTop+document.body.scrollTop;
        var h= document.documentElement.scrollHeight;
        return y>=h/2;
    }
    

    Browser compatibility notes: window.onscroll() is because IE doesn’t fire the scroll event when scrollTo() is used. Both html and body‘s scroll offsets have to be added together in isHalfwayDown() because the browsers unfortunately don’t agree on which element represents the viewport.

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

Sidebar

Related Questions

I'm completely new to the javascript and ajax world but trying to learn. Right
I'm not new to JavaScript, but I've never really had too much in-depth knowledge
I'm completely new to jQuery/javascript and have been beating my head against this simple
Well, I'm completely new to JavaScript. Can you please tell me what type of
I'm completely new to AIR but what I'm trying to do feels like it
I'm completely new to JQuery and MVC. I'm working on a pet project that
I am very new in JavaScript world. function ButtonClickAction2 (zEvent) { self.location=xxx.asp?action=go&Locale=2; } I
I'm new to jquery and javascript, and to web site developing overall, and I'm
We understand that JavaScript is single threaded, but we want to confirm our understanding
I want to use some animation in my page,so I google "javascript animation",I found

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.