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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 5, 20262026-06-05T06:03:28+00:00 2026-06-05T06:03:28+00:00

The webpage I’m trying to create has a bidirectional sliding animation on it. However

  • 0

The webpage I’m trying to create has a bidirectional sliding animation on it. However the animation is only partially working. To be more precise, the animation slides up, but it only slides down partway. Here’s my JavaScript:

function showLayer() {
var hiddenLayer = document.getElementById("mainmenu");
var layerPosition = parseInt(hiddenLayer.style.top);
if (layerPosition > 315) {
    hiddenLayer.style.top = (layerPosition - 5) + "px";
    setTimeout("showLayer()", 20);
}
}

function hideLayer() {
var hiddenLayer = document.getElementById("mainmenu");
var layerPosition = parseInt(hiddenLayer.style.top);
if (layerPosition <= 315) {
    hiddenLayer.style.top = (layerPosition + 5) + "px";
    setTimeout("hideLayer()", 20);
}
}

Notice on the fourth line of the hideLayer function, I have the condition set to <= 315, this is due to the fact that setting it equal to 315 causes the element to move only a few pixels in either direction after clicking the trigger element. Here’s the HTML elements I have dedicated to the animation:

<div id="mainbutton" onclick="showLayer('mainmenu'); hideLayer('mainmenu')"></div>
<div id="mainmenu" style="position: absolute; top: 690px; left: 9px;"  
onclick="showLayer('mainmenu')">&nbsp;</div>

And here are the styles for them:

div#mainmenu { width: 600px; height: 350px; border-style: solid; background-color: 
rgb(0, 0, 0) ; border-width: 3px; border-top-right-radius: 7px; border-top-left-
radius: 7px; }
div#mainbutton { position: absolute; top: 674px; left: 12px; width: 28px; height: 
28px; border-style: solid; border-color: rgb(255, 255, 255); border-width: 1px; border-
radius: 4px; }

And the fiddle : http://jsfiddle.net/JAtLA/

I had to put some of the styles inline with the HTML because the animation wouldn’t work any other way. At first I thought the problem had solely lain in the if conditional of the hideLayer function. But after tweaking it I’m not so sure now.

  • 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-05T06:03:29+00:00Added an answer on June 5, 2026 at 6:03 am

    It looks like “hideLayer” will stop if (layerPosition <= 315). Is that really what you want? It happens after 1 iteration.

    Note that the y axis goes down the screen (i.e. zero is at the top).

    Clicking the button will call showLayer, and then hideLayer.
    If the menu is open (i.e. layerPosition > 315), showLayer will not do anything (i guess that is what you intend), and hideLayer will make the menu go up by 5 (from 315 to 320).
    On the next iteration of hideLayer (layerPosition <= 315) will be false, so it will not do anything.

    Try this:

    var open = false;
    
    function showLayer() {
        if (open)
            return;
    
        var hiddenLayer = document.getElementById("mainmenu");
        var layerPosition = parseInt(hiddenLayer.style.top);
        if (layerPosition > 315) {
            hiddenLayer.style.top = (layerPosition - 5) + "px";
            setTimeout("showLayer()", 20);
        }
        else {
            open = true;
        }
    }
    
    function hideLayer() {
        if (!open)
            return;
    
        var hiddenLayer = document.getElementById("mainmenu");
        var layerPosition = parseInt(hiddenLayer.style.top);
        if (layerPosition <= 685) {
            hiddenLayer.style.top = (layerPosition + 5) + "px";
            setTimeout("hideLayer()", 20);
        }
        else {
            open = false;
        }
    }
    

    In the html, I would like to check if the thing is open or closed before doing anything.

    <div id="mainbutton" onclick="if (!open) { showLayer('mainmenu'); } else { hideLayer('mainmenu'); }">
    

    but layerPosition <= 685 is the only change that really matters.

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

Sidebar

Related Questions

The webpage has the following source (only copied the important part): <h1>Relatórios</h1> <div id=textmenu>
ActivePython webpage has a list of included things that includes something called OpenSSL version
My webpage allows users to select items from a dropdown list and has a
My webpage has a large image (a map). I want to position, at the
A webpage has a product code I need to retrive, and it is in
My webpage has a header image that always remains at the top of the
My webpage has a 'skinny' list: for example, a list of 100 items of
I have a webpage that has a Telerik RadComboBox in radgrid control on the
My webpage has a date field which uses javascript calendar. The format of the
The webpage that I'm trying to access is sending back a 403 error. I's

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.