Created
January 24, 2019 15:46
-
-
Save prof3ssorSt3v3/28080b87fa43bab8c992c9e35bf0aa35 to your computer and use it in GitHub Desktop.
Revisions
-
prof3ssorSt3v3 created this gist
Jan 24, 2019 .There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode charactersOriginal file line number Diff line number Diff line change @@ -0,0 +1,111 @@ <!DOCTYPE html> <html lang="en"> <head> <meta charset="UTF-8"> <meta name="viewport" content="width=device-width, initial-scale=1.0"> <meta http-equiv="X-UA-Compatible" content="ie=edge"> <title>SPA Demo</title> <style> *{ padding:0; margin:0; box-sizing: border-box; } html{ font-size: 16px; line-height: 1.7; font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, Oxygen, Ubuntu, Cantarell, 'Open Sans', 'Helvetica Neue', sans-serif; } .container{ min-height: 100vh; width: 100vw; overflow-x: hidden; background-color: #bada55; position: relative; } .page{ position: absolute; top: 0; left: 0; right: 0; /* display: none; */ opacity: 0; transform: translateY(-200%); transition: all 0.4s linear; } .active{ /* display: block; */ opacity: 1; transform: translateY(0); } #heena{ background-color: rebeccapurple; color: #f1f1f1;; } #lauren{ background-color: salmon; color: #333; } #luis{ background-color: red; color: chartreuse; } h1{ padding: 1rem 2rem; text-align: center; } </style> </head> <body> <main class="container"> <section class="page" id="lauren"> <h1 data-target="heena">This is page Lauren</h1> </section> <section class="page" id="heena"> <h1 data-target="luis">This is page Heena</h1> </section> <section class="page" id="luis"> <h1 data-target="lauren">This is page Luis</h1> </section> </main> <script> let app = { pages: null, init: function () { if(window.hasOwnProperty("cordova")){ console.log("You're on a mobile device"); } let isReady = (window.hasOwnProperty("cordova"))?'deviceready':'DOMContentLoaded'; document.addEventListener(isReady, ()=>{ app.pages = document.querySelectorAll('.page'); app.pages[1].classList.add('active'); app.pages.forEach( page => { page.querySelector('h1').addEventListener('click', app.navigate); }); }); }, navigate: function(ev){ ev.preventDefault(); let tapped = ev.currentTarget; //the clicked h1 console.log(tapped); document.querySelector('.active').classList.remove('active'); //hide the only active page let target = tapped.getAttribute('data-target'); document.getElementById(target).classList.add('active'); } }; app.init(); </script> </body> </html>