Page Transitions in Backbone
How do I make an page transitions in backbone?
An opinionated way to implement page transitions in a Backbone.js application. Part of a larger post found here: http://mikefowler.me/2013/11/18/page-transitions-in-backbone/. What is a page transitions in backbone? How do you make a page transitions in backbone? This script and codes were developed by Mike Fowler on 21 August 2022, Sunday.
Page Transitions in Backbone - Script Codes HTML Codes
<!DOCTYPE html>
<html >
<head> <meta charset="UTF-8"> <title>Page Transitions in Backbone</title> <style> /* NOTE: The styles were added inline because Prefixfree needs access to your styles and they must be inlined if they are on local disk! */ * { box-sizing: border-box;
}
body { margin: 0; padding: 0; font: 150% Futura-Medium, Futura, sans-serif; color: #333;
}
h1 { font-weight: normal;
}
a { color: #F2994B;
}
.page { position: absolute; top: 0; right: 0; bottom: 0; left: 0; padding: 1em; text-align: center; transition: transform 0.5s ease; transform: translate3d(100%, 0, 0);
}
.page a { color: white;
}
.page.is-visible { transform: translate3d(0, 0, 0);
}
.home { color: white; background: #F2CF66;
}
.activity { color: white; background: #F2994B;
}
.footer { position: fixed; bottom: 0; left: 0; width: 100%; padding: 10px; background: white; z-index: 10;
} </style> <script src="https://cdnjs.cloudflare.com/ajax/libs/prefixfree/1.0.7/prefixfree.min.js"></script>
</head>
<body> <footer class="footer" role="contentinfo"> <p>This demo is part of a post by Mike Fowler titled <a href="http://mikefowler.me/2013/11/18/page-transitions-in-backbone" target="page-transitions-in-backbone">“Page Transitions in Backbone”</a>.</p>
</footer>
<script type="text/template" name="home"> <h1>Home</h1> <p><a href="#/activity">Activity →</a></p>
</script>
<script type="text/template" name="activity"> <h1>Activity</h1> <p><a href="#/">← Home</a></p>
</script> <script src='http://cdnjs.cloudflare.com/ajax/libs/jquery/2.1.3/jquery.min.js'></script>
<script src='http://cdnjs.cloudflare.com/ajax/libs/underscore.js/1.5.2/underscore-min.js'></script>
<script src='http://cdnjs.cloudflare.com/ajax/libs/backbone.js/1.1.0/backbone-min.js'></script> <script src="js/index.js"></script>
</body>
</html>
Page Transitions in Backbone - Script Codes CSS Codes
* { box-sizing: border-box;
}
body { margin: 0; padding: 0; font: 150% Futura-Medium, Futura, sans-serif; color: #333;
}
h1 { font-weight: normal;
}
a { color: #F2994B;
}
.page { position: absolute; top: 0; right: 0; bottom: 0; left: 0; padding: 1em; text-align: center; transition: transform 0.5s ease; transform: translate3d(100%, 0, 0);
}
.page a { color: white;
}
.page.is-visible { transform: translate3d(0, 0, 0);
}
.home { color: white; background: #F2CF66;
}
.activity { color: white; background: #F2994B;
}
.footer { position: fixed; bottom: 0; left: 0; width: 100%; padding: 10px; background: white; z-index: 10;
}
Page Transitions in Backbone - Script Codes JS Codes
(function () { window.app = { Views: {}, Extensions: {}, Router: null, init: function () { this.instance = new app.Views.App(); Backbone.history.start(); } }; $(function() { window.app.init(); }); app.Router = Backbone.Router.extend({ routes: { 'activity': 'activity', '': 'home' }, home: function () { var view = new app.Views.Home(); app.instance.goto(view); }, activity: function () { var view = new app.Views.Activity(); app.instance.goto(view); } }); app.Extensions.View = Backbone.View.extend({ initialize: function () { this.router = new app.Router(); }, render: function(options) { options = options || {}; if (options.page === true) { this.$el.addClass('page'); } return this; }, transitionIn: function (callback) { var view = this, delay var transitionIn = function () { view.$el.addClass('is-visible'); view.$el.one('transitionend', function () { if (_.isFunction(callback)) { callback(); } }) }; _.delay(transitionIn, 20); }, transitionOut: function (callback) { var view = this; view.$el.removeClass('is-visible'); view.$el.one('transitionend', function () { if (_.isFunction(callback)) { callback(); }; }); } }); app.Views.App = app.Extensions.View.extend({ el: 'body', goto: function (view) { var previous = this.currentPage || null; var next = view; if (previous) { previous.transitionOut(function () { previous.remove(); }); } next.render({ page: true }); this.$el.append( next.$el ); next.transitionIn(); this.currentPage = next; } }); app.Views.Home = app.Extensions.View.extend({ className: 'home', render: function () { var template = _.template($('script[name=home]').html()); this.$el.html(template()); return app.Extensions.View.prototype.render.apply(this, arguments); } }); app.Views.Activity = app.Extensions.View.extend({ className: 'activity', render: function () { var template = _.template($('script[name=activity]').html()); this.$el.html(template()); return app.Extensions.View.prototype.render.apply(this, arguments); } });
}());
Developer | Mike Fowler |
Username | mikefowler |
Uploaded | August 21, 2022 |
Rating | 4 |
Size | 3,691 Kb |
Views | 50,600 |
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 |
IOS7 Geolocation Map Marker | 4,359 Kb |
Mixtape | 3,691 Kb |
Coverflow Animation | 2,864 Kb |
Nickname generator | 7,313 Kb |
Image Markers | 3,194 Kb |
A Pen by Mike Fowler | 3,067 Kb |
Rounded Avatar | 3,263 Kb |
Coverflow | 3,581 Kb |
Map Locator Marker | 4,026 Kb |
Navigation Indicator | 3,472 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 |
Main page display | BarryKe | 4,562 Kb |
CSS Social Media Icon | TychoBlender | 3,871 Kb |
CSS3 Latte Art Logo | Esambino | 2,036 Kb |
Wikipedia Viewer | Odylic | 2,333 Kb |
CSS Letter animations | Sladix | 2,116 Kb |
CSS Variables | Jdsteinbach | 4,759 Kb |
Background-blend-mode Test | 0x04 | 4,744 Kb |
Brian The CSS Bee | Jonitrythall | 3,922 Kb |
Contact | GanNichiHa | 2,514 Kb |
Clock with full screen background | Owebboy | 2,415 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!