css Audio - Active file-generic CSS - Active Generic - Active HTML - Active JS - Active SVG - Active Text - Active file-generic Video - Active header Love html icon-new-collection icon-person icon-team numbered-list123 pop-out spinner split-screen star tv

Pen Settings

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. If you link to another Pen, it will include the CSS from that Pen. If the preprocessor matches, it will attempt to combine them before processing.

+ add another resource

You're using npm packages, so we've auto-selected Babel for you here, which we require to process imports and make it all work. If you need to use a different JavaScript preprocessor, remove the packages in the npm tab.

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

Use npm Packages

We can make npm packages available for you to use in your JavaScript. We use webpack to prepare them and make them available to import. We'll also process your JavaScript with Babel.

⚠️ This feature can only be used by logged in users.

Code Indentation

     

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.

HTML Settings

Here you can Sed posuere consectetur est at lobortis. Donec ullamcorper nulla non metus auctor fringilla. Maecenas sed diam eget risus varius blandit sit amet non magna. Donec id elit non mi porta gravida at eget metus. Praesent commodo cursus magna, vel scelerisque nisl consectetur et.

            
              <!--Movie and quote posters-->
<div class = "container-fluid">
	<div class = "row images justify-content-center">
		<img class = "img-fluid movieHighlight main-poster" src = "" alt = "">
	</div>
	<div class = "row images justify-content-center">
		<img class = "img-fluid quoteHighlight main-poster" src = "" alt = "">
	</div>
</div>

<!--Twitter share button-->
<div class = "share-button">
</div>

<!--Credits to Marie Caballes for the graphics-->
<div class = "credits">
	<p class = "p-creds">© G: MC. WD: YC</p>
</div>
            
          
!
            
              /*make images responsive*/
.main-poster {
	object-fit: contain;
}

/*keep twitter button to top right of screen*/
.share-button {
	top: 0;
	right: 0;
	position: fixed;
}

/*keep credits to top left of screen*/
.credits {
	top: 0;
	left: 0;
	position: fixed;
	font-family: 'Oswald', sans-serif;
}
            
          
!
            
              //JSON of movie quotes and images
var quote = [
	{
		"num": 1,
		"movie": "3 Idiots",
		"quote": "All izz well.",
		"movieImg": "https://s13.postimg.org/7rngluplz/3_Idiots_2_1.jpg",
		"quoteImg": "https://s13.postimg.org/yk8kgd1mv/3_Idiots_2_2.jpg",
		"movieColor": "#fef278",
		"quoteColor": "#75bf34"
	}, {
		"num": 2,
		"movie": "12 Years a Slave",
		"quote": "I don't want to live. I want to survive.",
		"movieImg": "https://s13.postimg.org/cqaz0egk7/12_Years_a_Slave_1_1.jpg",
		"quoteImg": "https://s13.postimg.org/c8armzhyf/12_Years_a_Slave_1_2.jpg",
		"movieColor": "#eb2b36",
		"quoteColor": "#edeee9"
	}, {
		"num": 3,
		"movie": "August Rush",
		"quote": "Sometimes the world tries to knock it out of you. But I believe in music the way that some people believe in fairy tales.",
		"movieImg": "https://s13.postimg.org/3va4pvcc7/August_Rush_1_1.jpg",
		"quoteImg": "https://s13.postimg.org/a3qelwvrb/August_Rush_1_2.jpg",
		"movieColor": "#fba443",
		"quoteColor": "#49437f"
	}, {
		"num": 4,
		"movie": "Back to the Future",
		"quote": "When this baby hits 88 miles per hour, you're gonna see some serious shit.",
		"movieImg": "https://s13.postimg.org/a3qelxiwn/Back_to_the_Future_2_1.jpg",
		"quoteImg": "https://s13.postimg.org/bvjdgtmtz/Back_to_the_Future_2_2.jpg",
		"movieColor": "#515153",
		"quoteColor": "#e7654d"
	}, {
		"num": 5,
		"movie": "Becoming Jane",
		"quote": "My characters shall have, after a little trouble, all that they desire.",
		"movieImg": "https://s13.postimg.org/k6a8m6wjr/Becoming_Jane_1_1.jpg",
		"quoteImg": "https://s13.postimg.org/n7vyymio7/Becoming_Jane_1_2.jpg",
		"movieColor": "#f36f6d",
		"quoteColor": "#fef493"
	}, {
		"num": 6,
		"movie": "Dead Poets Society",
		"quote": "O captain, my captain.",
		"movieImg": "https://s13.postimg.org/zf05zz5nr/Dead_Poets_Society_1_1.jpg",
		"quoteImg": "https://s13.postimg.org/hwh2dxc13/Dead_Poets_Society_1_2.jpg",
		"movieColor": "#ace39f",
		"quoteColor": "#2a647a"
	}, {
		"num": 7,
		"movie": "Kingsman: The Secret Service",
		"quote": "I'm a Catholic whore, currently enjoying congress out of wedlock with my Jewish boyfriend who works at a military abortion clinic. So, hail Satan, and have a lovely afternoon, madam.",
		"movieImg": "https://s13.postimg.org/maulnalbr/Kingsman_2_1.jpg",
		"quoteImg": "https://s13.postimg.org/7menep9av/Kingsman_2_2.jpg",
		"movieColor": "#e8c88d",
		"quoteColor": "#e1ad35"
	}, {
		"num": 8,
		"movie": "The Godfather",
		"quote": "I'm gonna make him an offer he can't refuse.",
		"movieImg": "https://s13.postimg.org/kdstl7qsn/The_Godfather_3_1.jpg",
		"quoteImg": "https://s13.postimg.org/yk8kgg9dj/The_Godfather_3_2.jpg",
		"movieColor": "#e9e9e9",
		"quoteColor": "#bb2026"
	}
];

var prevQuote;
var currQuote;

//get new random quote from JSON quote
function newRandomQuote(){
	return quote[Math.floor(Math.random() * quote.length)];
};

/*INITIAL STATE
get two random quotes from JSON quote
and store them in var prevQuote and var currQuote*/
function loadReel(){
	prevQuote = newRandomQuote();
	
	var pendingQuote = newRandomQuote();
	//check if the same quote has been loaded twice, to avoid repeats
	while(pendingQuote["num"] === prevQuote["num"]){
		pendingQuote = newRandomQuote();
	};
	currQuote = pendingQuote;	
};

/*ONGOING STATE
get one random quote from JSON quote
and store it in var currQuote,
while old currQuote is stored in prevQuote*/
function rollReel(){
	var pendingQuote = newRandomQuote();
	while(pendingQuote.num === prevQuote.num || pendingQuote.num === currQuote.num){
		pendingQuote = newRandomQuote();
	};
	prevQuote = currQuote;
	currQuote = pendingQuote;	
};

//load quote values to html
function displayReel(){
	//change text and bg colors depending on currQuote
	$("body").css("background-color", currQuote.movieColor);
	$(".p-creds").css({
		"color": currQuote.quoteColor
	});
	
	//reset twitter text depending on currQuote	
  $(".share-button").html('<a	href="https://twitter.com/share" class="twitter-share-button" data-url="https://codepen.io/penpendesarapen/full/GyBBOe/" data-size="large" data-hashtags="quote" data-text="' + currQuote.quote + ' - ' + currQuote.movie + '" data-count="none"></a>');
	twttr.widgets.load();
	
	//change images depending on currQuote
	$(".movieHighlight").attr({
		"src": currQuote.movieImg,
		"alt": currQuote.movie
	});	
	$(".quoteHighlight").attr({
		"src": currQuote.quoteImg,
		"alt": currQuote.movie
	});	
};


//MAIN FUNCTION
$(document).ready(function(){
	loadReel();
	displayReel();
	$(".images").click(function(){
		rollReel();
		displayReel();
	});
});
            
          
!
999px
🕑 One or more of the npm packages you are using needs to be built. You're the first person to ever need it! We're building it right now and your preview will start updating again when it's ready.
Loading ..................

Console