<div class="quote-container">
<div class="quote-text">
<div class="icon">
<i class="fa fa-quote-left left-quote" aria-hidden="true"></i>
</div>
<blockquote>
</blockquote>
<span class="quote-author">
</span>
</div>
<div class="buttons">
<button class="btn-twitter">
<i class="fa fa-twitter" aria-hidden="true"></i>
</button>
<button class="btn-quote">
New quote
</button>
</div>
</div>
<footer>
by <a href="https://codepen.io/rizwanahmed19" target="_blank">Rizwan</a>
</footer>
@import 'https://fonts.googleapis.com/css?family=Lato:300,400';
@import 'https://fonts.googleapis.com/css?family=Satisfy';
body {
background-color: #333;
font-family: 'Lato', sans-serif;
font-size: 20px;
transition: background 0.5s ease;
}
.quote-container {
background-color: #fff;
border-radius: 2px;
width: 600px;
margin: 150px auto;
margin-bottom: 30px;
overflow: auto;
box-shadow: 0 10px 6px -6px #555;
}
.quote-text {
position: relative;
}
blockquote {
font-family: "Satisfy", cursive;
font-size: 135%;
margin: 0px auto;
margin-bottom: 20px;
margin-top: 50px;
color: #333;
text-align: center;
line-height: 140%;
width: 80%;
}
.icon {
position: absolute;
top: -4px;
left: 30px;
}
i.left-quote {
padding-right: 7px;
font-size: 135%;
color: #333;
line-height: 140%;
}
span {
display: block;
font-size: 90%;
font-weight: 300;
color: #333;
text-align: center;
margin: 0 auto;
}
.buttons {
padding: 20px;
}
button {
background-color: transparent;
border: none;
cursor: pointer;
}
.btn-twitter {
background-color: #333;
font-size: 130%;
padding: 4px 8px;
color: #fff;
margin-left: 25px;
border-radius: 3px;
vertical-align: middle;
transition: opacity 0.2s ease;
}
.btn-twitter:hover{
opacity: 0.8;
}
.btn-quote {
background-color: #333;
height: 35px;
color: #fff;
border-radius: 3px;
margin-bottom: 10px;
margin-left: 370px;
padding: 0 10px;
transition: opacity 0.2s ease;
}
.btn-quote:hover {
opacity: 0.8;
}
footer {
color: #fff !important;
font-size: 70%;
text-align: center;
}
footer a {
color: #fff;
}
var quotes = [
{
"quote" : "The wound is the place where the Light enters you.",
"author" : "-Rumi"
},
{
"quote" : "Do what you feel in your heart to be right, for you’ll be criticized anyway.",
"author" : "-Eleanor Roosevelt"
},
{
"quote" : "Be yourself; everyone else is already taken.",
"author" : "-Oscar Wilde"
},
{
"quote" : "Be there for others, but never leave yourself behind.",
"author" : "-Dodinsky"
},
{
"quote" : "He who is not courageous enough to take risks will accomplish nothing in life.",
"author" : "-Muhammad Ali"
},
{
"quote" : "I don’t regret the things I’ve done, I regret the things I didn’t do when I had the chance.",
"author" : "-Unknown"
},
{
"quote" : "I’d rather live with a good question than a bad answer.",
"author" : "-Aryeh Frimer"
},
{
"quote" : "We are what we repeatedly do; excellence, then, is not an act but a habit.",
"author" : "-Aristotle"
},
{
"quote" : "The true measure of a man is how he treats someone who can do him absolutely no good.",
"author" : "-Samuel Jackson"
},
{
"quote" : "You miss 100 percent of the shots you don't take.",
"author" : "-Wayne Gretzky"
}
];
var colors = ["#73A857", "#342224", "#2980b9", "#f1c40f", "#21894D", "#d35400", "#34495e", "#f39c12", "#8e44ad", "#7f8c8d"];
var ran; // to hold random number
var quote; // to hold random quote
var author; // to hold random quote author
/* get a random number b/w 0 and 9 */
function getRandomQuote(argument) {
ran = Math.floor(Math.random() * 10);
quote = quotes[ran].quote.split("");
author = quotes[ran].author.split("");
}
var quoteEffect;
var authorEffect;
var i = 0;
function typingEffect(){
quoteEffect = setInterval(function(){
var char = quote[i];
if (char === ",") {
i++;
char = quote[i];
}
$("blockquote").append(char);
i++;
if(i === quote.length){
clearInterval(quoteEffect);
i = 0;
authorEffect = setInterval(function() {
var char = author[i];
if (char === ",") {
i++;
char = author[i];
}
$(".quote-author").append(char);
i++;
if(i === author.length){
clearInterval(authorEffect);
i = 0;
}
},50);
}
}, 90);
}
function setCSS() {
var randomInt = Math.floor(Math.random() * 10);
$("body").css({
"background-color": colors[randomInt],
"color": colors[randomInt]
});
$("blockquote").css({
"color": colors[randomInt]
});
$(".quote-author").css({
"color": colors[randomInt]
});
$(".left-quote").css({
"color": colors[randomInt]
});
$(".btn-quote").css({
"background-color": colors[randomInt],
});
$(".btn-twitter").css({
"background-color": colors[randomInt],
});
}
$(document).ready(function($) {
getRandomQuote();
typingEffect();
setCSS();
$(".btn-quote").click(function(event) {
/* Act on the event */
i = 0;
$("blockquote").empty();
$(".quote-author").empty();
clearInterval(quoteEffect);
clearInterval(authorEffect);
getRandomQuote();
typingEffect();
setCSS();
});
$(".btn-twitter").click(function(event) {
window.open("https://www.twitter.com/intent/tweet?text=" + encodeURIComponent('"' + quote.join("") + '"' + " " + author.join("")));
});
});