Pen Settings

HTML

CSS

CSS Base

Vendor Prefixing

Add External Stylesheets/Pens

Any URL's added here will be added as <link>s in order, and before the CSS in the editor. You can use the CSS from another Pen by using it's URL and the proper URL extention.

+ add another resource

JavaScript

Babel includes JSX processing.

Add External Scripts/Pens

Any URL's added here will be added as <script>s in order, and run before the JavaScript in the editor. You can use the URL of any other Pen and it will include the JavaScript from that Pen.

+ add another resource

Packages

Add Packages

Search for and use JavaScript packages from npm here. By selecting a package, an import statement will be added to the top of the JavaScript editor for this package.

Behavior

Save Automatically?

If active, Pens will autosave every 30 seconds after being saved once.

Auto-Updating Preview

If enabled, the preview panel updates automatically as you code. If disabled, use the "Run" button to update.

Format on Save

If enabled, your code will be formatted when you actively save your Pen. Note: your code becomes un-folded during formatting.

Editor Settings

Code Indentation

Want to change your Syntax Highlighting theme, Fonts and more?

Visit your global Editor Settings.

HTML

              
                <link href='//fonts.googleapis.com/css?family=Signika+Negative:300' rel='stylesheet' type='text/css'>

<div id="app">
  <div id="loading" class="page">
    <p>LOADING...</p>
  </div>

  <div id="home" class="page" style="display:none">
    <ul class="nav">
      <li class="btn" data-selected="one">Start Game</li>
      <li class="btn" data-selected="two">Instructions</li>
      <li class="btn" data-selected="three">Page 3</li>
    </ul>
    <div class="instructions">
      choose option
    </div>
  </div>

  <div id="one" class="page" style="display:none" >
    <h1>Game</h1>
    <button class="home_btn">home</button>
  </div>
  <div id="two" class="page" style="display:none">
    <h1>Instructions</h1>
    <button class="home_btn">home</button>
  </div>
  <div id="three" class="page" style="display:none">
    <h1>Page 3</h1>
    <button class="home_btn">home</button>
  </div>
</div>
              
            
!

CSS

              
                body, html {
  font-family: Signika Negative, sans-serif;
  background: #111;
  color:#efefef;
  height:100%;
}

#app {
  width: 350px;
  display: block;
  margin: 0 auto;
}

#loading{
  display:block;
  text-align:center;
  height:100%
}
#loading p {
  margin-top:100px;
  font-size:40px
}

.btn {
  border: none;
  text-align:center;
  cursor: pointer;
  padding: 25px 80px;
  margin: 25px 30px;
  text-transform: uppercase;
  letter-spacing: 1px;
  font-weight: 700;
  outline: none;
  position: relative;
  background-color:rgb(38, 38, 38);
  border: solid 1px transparent;
  border-radius:10px;
  -webkit-font-smoothing: antialiased;
}

.nav {
  position:relative;
  width:350px;
  margin:auto;
  overflow:hidden;
  background-color:#1d1d1d;
  height:90%;
  visibility:hidden;
  list-style-type: none;
}

.page {
  position:fixed;
  width:350px;
  margin:auto;
  overflow:hidden;
  height:90%;

}


.instructions {
  text-align:center;
  margin-top:10px;  
}

h1 {
  text-align:center
}


.home_btn {
  display:block;
  margin: 200px auto 0 auto;
}


#one{background-color : blue}
#two{background-color : red}
#three{background-color : green}
              
            
!

JS

              
                //test Jquery extension to crossfade using greensock

(function ($) {

  $.fn.xFade = function (element, userOptions, callback) {
    // retrieve arguments as array
    var args = new Array(arguments.length);
    for (var i = 0; i < args.length; ++i) {
      args[i] = arguments[i];
      console.log(i);
    };
    var hasCallback = false;
    var secondStartTime;

    var tl = new TimelineMax();

    toElement = args.shift();
    console.log(args[args.length -1]);
    if (typeof args[args.length - 1] === 'function') {
      callback = args.pop();
      console.log("has a callback")
      hasCallback = true;
    } 

    if (args.length > 0) options = args.shift(); 
    var opts = $.extend({}, $.fn.xFade.defaults, options);
    console.log(opts);
    var parsedPercentage = parseFloat(opts.crossPoint);
    console.log(parsedPercentage)

    if (opts.effectDurataion && parsedPercentage >= 0 && parsedPercentage <= 100) {
      secondStartTime = (opts.effectDurataion * (1 - parsedPercentage / 100));
    } else {
      console.log("invalid percentatge or using defaults")
      secondStartTime = opts.effectDurataion * (1 - parseFloat(opts.crossPoint) / 100);
    }

    console.log(`Effect duration ${opts.effectDurataion}s, cross point@ ${opts.crossPoint} second start time ${secondStartTime}s`)
    tl.set(toElement, { autoAlpha: 0, clearProps: "display" }) //clear display prop so element can be initially hidden?
      .to(this, opts.effectDurataion, { autoAlpha: 0, ease: Power0.easeNone }) //fade first elemet out
      .to(toElement, opts.effectDurataion, { autoAlpha: 1, ease: Power0.easeNone}, "-=" + secondStartTime) //fade second elemet in with time offset
      .eventCallback("onComplete", function () {
        if (hasCallback) {
         console.log("running callback");
          callback();
        } else {console.log("no callback")};
      }  
      );
  }

  $.fn.xFade.defaults = {
    effectDurataion: .6,
    crossPoint: "50%",
    easeIn: "", //to be added?
    easeOutType: "", //to be added?
    calbackDelayOffset : "0" // pre delay t fire callback before fade in animation //to be added
  }
  
}(jQuery));




$(document).ready(function () {

  var lastState;
  var newState;

  //delay to simulate page loading..
  setTimeout(function () {
startApp();
  }, 1500);


  function startApp() {
console.log("starting app..")
    $('#loading').xFade('#home', {effectDurataion: 0.6, crossPoint: "100%"}, 
    function() {menuEntrance(function () {
        console.log("Menu loaded and animation complete")
      })
    })
  }

   
  //button navigation
  $('.btn').on('click', function () {
    newState = $(this).data('selected');
    menuExit(function () {
      $("#home").xFade("#" + newState, {effectDurataion: .4, crossPoint: "100%"});
    });

    lastState = newState;
  });

  // home button click return home 
  $(".home_btn").on('click', function () {
    console.log("home clicked");
    $("#" + lastState).xFade("#home",{effectDurataion: .3, crossPoint: "0%"}, function () {
      menuEntrance(function () {
        console.log("Returned to home menu");
      });
    });
  });


  //Start menu entrance animations
  function menuEntrance(callback) {
    console.log("menu entrance called");
    var timeline = new TimelineMax();
    timeline
      .set(".btn", {
        visibility: "visible",
        y: 0,
        opacity: 0,
        scale: 0.5
      })
      .staggerTo(".btn", 2, { scale: 1, opacity: 1, delay: 0.5, ease: Elastic.easeOut, force3D: true }, 0.2)
      .eventCallback("onComplete", function () {
        console.log('on complete entrance callback')
        if (callback) { callback() }
      });
  };

 //Start menu exit animations
  function menuExit(callback) {
    console.log("menu exit called");
    var timeline = new TimelineMax();
    console.log("menu exit");
    timeline.staggerTo(".btn", 0.5, { opacity: 0, y: -100, ease: Back.easeIn }, 0.1)
      .eventCallback("onComplete", function () {
        console.log('on complete exit resolving')
        if (callback) { callback() }
      });
  };


});
              
            
!
999px

Console