Pen Settings

HTML

CSS

CSS Base

Vendor Prefixing

Add External Stylesheets/Pens

Any URLs 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 its URL and the proper URL extension.

+ 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

Auto Save

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

              
                <div id="book-content" class="container"></div>

<script type="text/template" id="book-template">
	<div class="row">
		<div class="col-xs-10 col-xs-offset-1 book">
			<img id="hardcover" class="img-responsive" src="https://dl.dropboxusercontent.com/s/t3uq5yi1p5yiqwa/old_book_cover_texture.png?dl=0" />
			<div id="placeholder"></div>
			<div id="flipcontent">
				<div id="pages">
					<div id="first-page"></div>
					<div></div>
					<div id="second-page"></div>
				</div>
			</div>
		</div>
	</div>
	<div class="row">
		<div class="col-xs-12 flip-control">
			<span id="prev-button" class="fa-stack">
				<i class="fa fa-circle-o fa-stack-2x"></i>
				<i class="fa fa-fast-backward fa-stack-1x"></i>
			</span>
			<span id="play-button" class="fa fa-play-circle-o"></span>
			<span id="next-button" class="fa-stack">
				<i class="fa fa-circle-o fa-stack-2x"></i>
				<i class="fa fa-fast-forward fa-stack-1x"></i>
			</span>
		</div>
	</div>
</script>

<script type="text/template" id="quote-template">
	<div class="row quote-content">
		<div class="col-xs-12">
			<blockquote>
				<p>
					&#8220;&nbsp;<%=quoteText%>&nbsp;&#8221;
				</p>
				<footer class="pull-right">
					<cite><%=quoteAuthor%></cite>
				</footer>
			</blockquote>
		</div>
		<div class="col-xs-12 share-links">
			<a class="fa fa-twitter-square text-primary" href="<%=twitterShareLink%>" target="_blank"><i>Share&nbsp;on&nbsp;twitter</i></a>&ensp;
			<a class="fa fa-google-plus-square text-primary" href="<%=googleShareLink%>" target="_blank"><i>Share&nbsp;on&nbsp;google+</i></a>
		</div>
	</div>
</script>
              
            
!

CSS

              
                @import url(https://fonts.googleapis.com/css?family=Kaushan+Script);
@import url(https://fonts.googleapis.com/css?family=Engagement);

body {
	min-width: 680px;
	background-image: url("https://dl.dropboxusercontent.com/s/dcadftwjlhg0wed/table_background.jpg?dl=0");
	background-size: cover;
	background-position: center;
	padding-top: 5%;
}

.book {
	position: relative;
	padding: 0;
}

#flipcontent {
	position: absolute;
}

#placeholder {
	position: absolute;
	background-color: ghostwhite;
}

#pages .turn-page {
	background-color: ghostwhite;
	background-image: url("https://dl.dropboxusercontent.com/s/oh5bf07zgkkj843/paper_texture.jpg?dl=0");
	background-size: cover;
}

.quote-content {
	height: 100%;
	display: flex;
	flex-direction: column;
	justify-content: center;
	align-items: center;
	padding: 1em 2em 2em 2em;
	font-family: "Kaushan Script";
	color: #32538c;
}

.quote-content blockquote {
	border-left: none;
}

.quote-content blockquote > footer {
	color: #5d7194;
}

.quote-content .share-links {
	margin-top: 1em;
}

.quote-content .share-links a {
	outline: 0;
}

.quote-content .share-links a > i {
	font-family: "Engagement";
	font-size: 1.2em;
	margin-left: 0.3em;
}

.flip-control {
	height: 6em;
	display: flex;
	flex-direction: row;
	justify-content: center;
	align-items: center;
}

.flip-control .fa {
	color: ghostwhite;
	text-shadow: 3px 3px 3px rgba(0, 0, 0, 0.4);
	cursor: pointer;
}

.flip-control span.fa {
	font-size: 4em;
}

.flip-control .fa-stack {
	font-size: 1.8em;
}

.flip-control .fa:hover,
.flip-control .fa-stack:hover .fa {
	color: lightgoldenrodyellow;
}

.flip-control span.fa:hover {
	font-size: 4.5em;
}

.flip-control .fa-stack:hover {
	font-size: 2em;
}

#prev-button.unactive .fa {
	color: rgba(200, 200, 200, 0.8);
	text-shadow: 3px 3px 3px rgba(100, 100, 100, 0.4);
}
              
            
!

JS

              
                var Quote = Backbone.Model.extend({
	urlRoot: "https://api.forismatic.com/api/1.0/?method=getQuote&lang=en&format=jsonp&jsonp=?",
	parse: function(response) {
		if (!response.quoteAuthor)
			response.quoteAuthor = "Unknown";
		response.twitterShareLink = "https://twitter.com/share?text=" + encodeURIComponent(response.quoteText + " - " + response.quoteAuthor) + "&url=" + response.quoteLink;
		response.googleShareLink = "https://plus.google.com/share?url=" + response.quoteLink;
		return response;
	}
});

var QuoteView = Backbone.View.extend({
	template: _.template($("#quote-template").html()),
	initialize: function() {
		this.model.on("change", this.render, this);
		this.model.fetch();
	},
	render: function() {
		if (this.model)
			this.$el.html(this.template(this.model.attributes));
		return this;
	}
});

var BookView = Backbone.View.extend({
	el: $("#book-content"),
	template: _.template($("#book-template").html()),
	events: {
		"click #prev-button": "prevPage",
		"click #next-button": "nextPage",
		"click #play-button": "playPages"
	},
	ui: {
		pages: "#pages",
		hardcover: "#hardcover",
		placeholder: "#placeholder",
		flipcontent: "#flipcontent",
		firstPage: "#first-page",
		secondPage: "#second-page",
		prevButton: "#prev-button",
		playButton: "#play-button",
		nextButton: "#next-button"
	},
	loadHtmlString: `<div class="quote-content">
		<i class="fa fa-circle-o-notch fa-spin fa-3x fa-fw"></i>
		<span class="sr-only">Loading...</span>
	</div>`,
	hPadding: 40,
	vPadding: 30,
	flipInterval: 5000,
	flipIntervalId: null,
	initialize: function(options) {
		this.options = options || {};
		if(_.isString(this.options.loadHtmlString))
			this.loadHtmlString = this.options.loadHtmlString;
		if(_.isNumber(this.options.hPadding))
			this.hPadding = this.options.hPadding;
		if(_.isNumber(this.options.vPadding))
			this.vPadding = this.options.vPadding;
		if(_.isNumber(this.options.flipInterval))
			this.flipInterval = this.options.flipInterval;
		
		_.bindAll(this, "resize", "render", "renderBook", "nextPage");
		$(window).on("resize", this.resize);
		this.render();
	},
	render: function() {
		this.$el.html(this.template());
		
		for(var el in this.ui) {
			this.ui[el] = $(this.ui[el]);
		}
		
		this.ui.hardcover.on("load", this.renderBook);
		
		var pagesTopSpacing = Math.floor(this.vPadding / 2),
				pagesSideSpacing = Math.floor(this.hPadding / 2);
		this.ui.placeholder.css("top", pagesTopSpacing).css("right", pagesSideSpacing);
		this.ui.flipcontent.css("top", pagesTopSpacing).css("left", pagesSideSpacing);
	},
	renderBook: function() {		
		this.ui.pages.hide();
		this.ui.placeholder.html(this.loadHtmlString);
		this.ui.placeholder.width(Math.floor((this.ui.hardcover.width() - this.hPadding) / 2)).height(this.ui.hardcover.height() - this.vPadding);
		
		this.ui.firstPage.html(this.loadHtmlString); 
		this.ui.secondPage.html(this.loadHtmlString);
	
		var firstQuote = new Quote(),
				firstQuoteView = new QuoteView({
					model: firstQuote,
					el: this.ui.firstPage
				}),
				secondQuote = new Quote(),
				secondQuoteView = new QuoteView({
					model: secondQuote,
					el: this.ui.secondPage
				});
		
		this.ui.pages.turn({ pages: 200 });
		this.ui.pages.bind("turning", { view: this }, function(e, page) {
			var view = e.data.view,
					range = $(this).turn("range", page);
			if(page === 1)
				view.ui.prevButton.addClass("unactive");
			else if(page === 2)
				view.ui.prevButton.removeClass("unactive");
			for (page = range[0]; page <= range[1]; page++)
				view.addPage(page, $(this));
		});
		
		this.resize();
		this.ui.pages.show();
		this.ui.placeholder.hide();
		
		this.ui.prevButton.addClass("unactive");
	},
	addPage: function(page, book) {
		if (!book.turn("hasPage", page)) {
			if (page % 2 === 0) {
				var element = $("<div />");
				book.turn("addPage", element, page);
			} else {
				var element = $("<div />").html(this.loadHtmlString);
				book.turn("addPage", element, page);
				var quote = new Quote(),
						quoteView = new QuoteView({
							model: quote,
							el: element
						});
			}
		}
	},
	nextPage: function() {
		this.ui.pages.turn("next");
	},
	prevPage: function() {
		this.ui.pages.turn("previous");
	},
	playPages: function() {
		if(this.ui.playButton.hasClass("fa-play-circle-o")) {
			this.nextPage();
			this.flipIntervalId = setInterval(this.nextPage, this.flipInterval);
		}
		else
			clearInterval(this.flipIntervalId);
		this.ui.playButton.toggleClass("fa-play-circle-o fa-pause-circle-o");
	},
	resize: function() {
		this.ui.pages.turn("size", this.ui.hardcover.width() - this.hPadding, this.ui.hardcover.height() - this.vPadding);
	}
});

$(document).ready(function() {
	var bookView = new BookView({ flipInterval: 10000 });
});
              
            
!
999px

Console