The `app` object
How do I make an the `app` object?
The simple app object defining routes and "life cycle" like functions.. What is a the `app` object? How do you make a the `app` object? This script and codes were developed by Heydon on 27 August 2022, Saturday.
The `app` object - Script Codes HTML Codes
<!DOCTYPE html>
<html >
<head> <meta charset="UTF-8"> <title>The `app` object</title> <link rel="stylesheet" href="css/style.css">
</head>
<body> <nav role="navigation"> <ul> <li><a href="#the-default-view">the default view</a></li> <li><a href="#some-view">some view</a></li> <li><a href="#another-view">another view</a></li> </ul>
</nav>
<main role="main"> <div id="some-view"> <h1>Some view</h1> <p>This is one of any number of views that are reachable by linking to its <code>id</code> / hash identifier.</p> </div> <div id="another-view"> <h1>Another view</h1> <p>This is one of any number of views that are reachable by linking to its <code>id</code> / hash identifier.</p> </div> <div id="the-default-view"> <h1>The default view</h1> <p>This view is visible by default when the user first arrives at the app.</p> </div>
</main> <script src="js/index.js"></script>
</body>
</html>
The `app` object - Script Codes CSS Codes
/* basic layout */
body { font-size: 120%; font-family: sans-serif; max-width: 40em; margin: 0 auto;
}
nav { text-align: center; padding: 0.5em 0; border-bottom: 2px solid;
}
nav li { display: inline-block; margin: 0 0.5em;
}
/* view visibility logic and animation */
main > * { display: none;
}
main > *:last-child { display: block;
}
@keyframes pulse { 0% { transform: scale(1) } 50% { transform: scale(1.05) } 100% { transform: scale(1) }
}
main > *:target { display: block; animation: pulse 0.5s linear 1;
}
main > *:target ~ * { display: none;
}
The `app` object - Script Codes JS Codes
(function() { var app = { // routes (ie. views and their functionality) defined here 'routes': { 'some-view': { 'rendered': function() { console.log('this view is "some-view"'); } }, 'another-view': { 'rendered': function() { console.log('this view is "another-view"'); app.routeElem.innerHTML = '<p>This javascript content overrides the static content for this view.</p>'; } } }, // The default view is recorded here. A more advanced implementation // might query the DOM to define it on the fly 'default': 'the-default-view', 'routeChange': function() { app.routeID = location.hash.slice(1); app.route = app.routes[app.routeID]; app.routeElem = document.getElementById(app.routeID); if (app.route) { app.route.rendered(); } }, // The function to start the app. 'init': function() { window.addEventListener('hashchange', function() { app.routeChange(); }); // If there's no hash in the URL, change the URL to // include the default view's hash if (!window.location.hash) { window.location.hash = app.default; } else { // Execute routeChange() for the first time app.routeChange(); } } }; window.app = app;
})();
app.init();
Developer | Heydon |
Username | heydon |
Uploaded | August 27, 2022 |
Rating | 3.5 |
Size | 2,590 Kb |
Views | 32,384 |
Find the perfect freelance services for your business! Fiverr's mission is to change how the world works together. Fiverr connects businesses with freelancers offering digital services in 500+ categories. Find Developer!
Name | Size |
Ransom Note With Google Font Subsets | 2,217 Kb |
4 columns, no single remainder | 1,563 Kb |
Vue.js TODO List | 4,218 Kb |
Focus management of smooth scrolling | 2,506 Kb |
Controlled chaos | 1,562 Kb |
Redesigned gender form field | 1,160 Kb |
Content Aware Navigation | 1,950 Kb |
Bookish | 2,094 Kb |
Hash change logging | 2,134 Kb |
CSS only, automated, and accessible external link icon | 1,678 Kb |
Jasper is the AI Content Generator that helps you and your team break through creative blocks to create amazing, original content 10X faster. Discover all the ways the Jasper AI Content Platform can help streamline your creative workflows. Start For Free!
Name | Username | Size |
Learning FlexBox | Alex_rodrigues | 2,821 Kb |
Experiment | Toddmoy | 2,849 Kb |
Board Site | IndianaLuft | 10,542 Kb |
Exploding Text | Jjmartucci | 4,749 Kb |
SVG Icons Template | Legofsalmon | 2,618 Kb |
Portfolio Page | KaylaMT | 1,983 Kb |
Product item | Mymahesh11 | 2,256 Kb |
Google Fonts Sass Mixin | HugoGiraudel | 4,237 Kb |
Testimonial Fancy tabs responsive | Amit-webdesigner | 3,056 Kb |
Yuliya v krylova | Rafszul | 37,351 Kb |
Surf anonymously, prevent hackers from acquiring your IP address, send anonymous email, and encrypt your Internet connection. High speed, ultra secure, and easy to use. Instant setup. Hide Your IP Now!