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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 12, 20262026-06-12T07:32:40+00:00 2026-06-12T07:32:40+00:00

First of all, here is the basic code for the site I need help

  • 0

First of all, here is the basic code for the site I need help with:
check bottom for edit

I’d like some help with the animation itself, because if I’m at div 1 and press any key, it works like a charm. But if I’m at div 3 and want to go to div 2, for example, it first loads div 1 and then goes to div 2. I know why it does it, but I can’t think of a way to go around it. Any ideas?

I’d also like to pause the function from inputs if the animation is already playing (so you can’t spam numbers and mess up the animation). How could I do that in an easy way?

Thanks!

EDIT

Due to a few very nice guys asking for me not being lazy, OP delivers:
http://jsfiddle.net/G4PXj/7

Also; http://codepen.io/anon/pen/zJsBH

Also, press HTML-box, then 2,3 or 4 and wait a few seconds for the animation to load into FOV.

HTML:

<div id="fourth" class="hidden">Fourth box
    <button onClick="fubar('first');">First page</button>
</div>
<div id="third" class="hidden">Third div</div>
<div id="second" class="hidden">Som text in the second</div>
<div id="first">Some content
    <button onClick="fubar('second');">Second page</button>
</div>

Style:

@charset "utf-8";
body {
    background-color: #fff;
    margin: 0;
    padding: 0;
    overflow: hidden;
}
#first {
    width: 100%;
    height: 100%;
    position: absolute;
    top: 0;
    color: #fff;
    box-shadow: 0 0 40px #333;
    background-color: #000;
}
#second {
    width: 100%;
    height: 100%;
    position: absolute;
    top: 0;
    background-color: green;
}
#third {
    width: 100%;
    height: 100%;
    position: absolute;
    top: 0;
    background-color: red;
}
#fourth {
    width: 100%;
    height: 100%;
    position: absolute;
    top: 0;
    background-color: blue;
}
.hidden {
    display: none;
}
.test {
    -moz-animation-name: wat;
    -webkit-animation-name: wat;
    -moz-animation-duration: 4s;
    -webkit-animation-duration: 4s;
    -moz-animation-timing-function: ease-out;
    -webkit-animation-timing-function: ease-out;
    -moz-animation-iteration-count: 1;
    -webkit-animation-iteration-count: 1;
    -moz-animation-direction: normal;
    -webkit-animation-direction: normal;
    z-index: 100;
    display: block;
}
@-moz-keyframes wat {
    0% {margin-left:-3000px;}
    60% {margin-left: 200px;}
    100% {margin-left: 0;}
}
@-webkit-keyframes wat {
    0% {margin-left:-3000px;}
    60% {margin-left: 200px;}
    100% {margin-left: 0;}
}

Javascript:

function clearAll() {
    document.getElementById('first').className = '';
    document.getElementById('second').className = '';
    document.getElementById('third').className = '';
    document.getElementById('fourth').className = '';
}

function troll(objectID) {
    document.getElementById(objectID).className += ' test';
}

function fubar(objectID) {
    clearAll();
    troll(objectID);
}

function KeyCheck(e) {
    var KeyID = (window.event) ? event.keyCode : e.keyCode;
    switch (KeyID) {

    case 49:
        clearAll();
        troll('first');
        break;

    case 50:
        clearAll();
        troll('second');
        break;

    case 51:
        clearAll();
        troll('third');
        break;

    case 52:
        clearAll();
        troll('fourth');
        break;
    }
}
document.onkeyup = KeyCheck;
  • 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-12T07:32:41+00:00Added an answer on June 12, 2026 at 7:32 am

    You could keep track of the previous page so that its z-index remains.

    // CSS
    .page{
      z-index: 0;
      // your other page settings
    }
    .previous{
      z-index: 99;
    }
    .test{
      z-index: 100;
      // your animation settings
    }
    

    Code :

    document.getElementById('button1').onclick = function(){ gotoPage('first'); }
    document.getElementById('button2').onclick = function(){ gotoPage('second'); }
    var previous, current;
    
    function gotoPage(id){
        // simplified className manipulation
        if(previous) previous.className = 'page';
        previous = current;
        if(previous) previous.className = 'page previous';
        current = document.getElementById(id);
        current.className = 'page test';
    }
    
    // key detection, etc.
    

    jQuery version :

    // JS
    $('#button1').click(function(){ gotoPage('first'); });
    $('#button2').click(function(){ gotoPage('second'); });
    var $previous, $current;
    
    function gotoPage(id){
      if($previous) $previous.removeClass('previous');
      $previous = $current;
      if($previous) $previous.removeClass('test').addClass('previous');
      $current = $('#' + id).addClass('test').removeClass('hidden');
    }
    
    // key detection, etc.
    

    Fiddle : http://jsfiddle.net/G4PXj/9/

    This ensures a pages layout with the following z-indexes : 100 for current (i.e. the animated page, you want it to be displayed above all others), 99 for previous (the page you are leaving : display above all the others, but still behind the animated page) and 0 for the rest, which are pages unrelated to the animation.

    The gotoPage() function sets the page you are leaving (i.e. current) to previous, and the page you want to reach (i.e. document.getElementById(id)) to current. The layout then applies to these new pages settings.

    As for pauses, here is a great example in this related question :
    How to pause and resume CSS3 animation using JavaScript?

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

Sidebar

Related Questions

Hopefully I'll get some help here. Basic setup is this: My application swaps out
First of all i'm new in here and new with csharp. just exhausted while
First of all I've gone through dozens of posting here on SO and google
First of all I know similar questions has been asked here, I've checked but
first of all this is my third question about web services here and i
First of all, I could not decide if I should ask this here or
First of all, I know there are a few quite similar questions here on
First of all, I do not believe this belongs on Superuser. This belongs here
um, first post here, this place seems to be all over google and i
first of all some details: I configured security as below in web.xml view plaincopy

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.