Lightweight Quiz Widget
How do I make an lightweight quiz widget?
Just a quick prototype of a lightweight quiz widget built with Javascript. . What is a lightweight quiz widget? How do you make a lightweight quiz widget? This script and codes were developed by Joshua P. Larson on 23 July 2022, Saturday.
Lightweight Quiz Widget - Script Codes HTML Codes
<!DOCTYPE html>
<html >
<head> <meta charset="UTF-8"> <title>Lightweight Quiz Widget</title> <meta name="viewport" content="width=device-width" /> <link rel="stylesheet" href="https://cdnjs.cloudflare.com/ajax/libs/normalize/5.0.0/normalize.min.css"> <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! */ *, *::before, *::after { -webkit-box-sizing: border-box; box-sizing: border-box;
}
html, body { width: 100%; height: 100%;
}
body { background: linear-gradient(#666, #333); padding: 1em;
}
.quiz { max-width: 40rem; margin: 2rem auto; background: #efefef; border-radius: 5px; overflow: hidden;
}
h2 { font-weight: 100; padding: 0.5em; background: #fafafa; margin: 0;
}
.questions { font-family: Georgia, serif; font-style: italic; font-size: 1.2em; padding: 1em;
}
@media all and (min-width: 30em) { .questions { width: 70%; }
}
.answers { background: #333; color: #fff; overflow: auto;
}
.answers input { display: none;
}
.answers input:checked ~ label { background: radial-gradient(#000000, #333333);
}
.answers label { display: block; float: left; width: 50%; padding: 1em; cursor: pointer; font-weight: 100; text-transform: uppercase; text-align: center;
}
@media all and (min-width: 30em) { .answers { width: 30%; } .answers label { float: none; width: 100%; }
}
.response { background: #ccc; font-weight: 100; max-height: 0; overflow: hidden; opacity: 0; transition: all 0.4s ease-in-out;
}
.response.open { padding: 1em; opacity: 1; max-height: 500px;
}
button { background: #3bb395; display: block; color: #fff; text-transform: uppercase; font-size: 0.9em; padding: 1em; border: 0; width: 100%;
}
button:hover { background: #2e8d75;
}
@media all and (min-width: 30em) { .qa { display: flex; }
} </style> <script src="https://cdnjs.cloudflare.com/ajax/libs/prefixfree/1.0.7/prefixfree.min.js"></script>
</head>
<body> <div class="quiz"> <h2>Should you go to college in Iowa?</h2> <div class="qa"> <div class="questions"></div> <div class="answers"> <div class="answer"> <input type="radio" name="answer" value="yes" id="yes" /><label for="yes"> Yes</label> </div> <div class="answer"> <input type="radio" name="answer" value="no" id="no" /><label for="no"> No</label> </div> </div> </div> <div class="response"></div> <button id="next">Next</button>
</div> <script src='http://cdnjs.cloudflare.com/ajax/libs/jquery/2.1.3/jquery.min.js'></script> <script src="js/index.js"></script>
</body>
</html>
Lightweight Quiz Widget - Script Codes CSS Codes
*, *::before, *::after { -webkit-box-sizing: border-box; box-sizing: border-box;
}
html, body { width: 100%; height: 100%;
}
body { background: linear-gradient(#666, #333); padding: 1em;
}
.quiz { max-width: 40rem; margin: 2rem auto; background: #efefef; border-radius: 5px; overflow: hidden;
}
h2 { font-weight: 100; padding: 0.5em; background: #fafafa; margin: 0;
}
.questions { font-family: Georgia, serif; font-style: italic; font-size: 1.2em; padding: 1em;
}
@media all and (min-width: 30em) { .questions { width: 70%; }
}
.answers { background: #333; color: #fff; overflow: auto;
}
.answers input { display: none;
}
.answers input:checked ~ label { background: radial-gradient(#000000, #333333);
}
.answers label { display: block; float: left; width: 50%; padding: 1em; cursor: pointer; font-weight: 100; text-transform: uppercase; text-align: center;
}
@media all and (min-width: 30em) { .answers { width: 30%; } .answers label { float: none; width: 100%; }
}
.response { background: #ccc; font-weight: 100; max-height: 0; overflow: hidden; opacity: 0; transition: all 0.4s ease-in-out;
}
.response.open { padding: 1em; opacity: 1; max-height: 500px;
}
button { background: #3bb395; display: block; color: #fff; text-transform: uppercase; font-size: 0.9em; padding: 1em; border: 0; width: 100%;
}
button:hover { background: #2e8d75;
}
@media all and (min-width: 30em) { .qa { display: flex; }
}
Lightweight Quiz Widget - Script Codes JS Codes
/** * Want to fork this? * Just click Fork above and change the questions below to your liking. * * TODO: * Maybe make a progress tracker at the bottom with total # of questions. */
var questions = [ { "q": "Do you like both hot and cold weather?", "a": { "yes": "Good! It's both hot and cold in Iowa.", "no": "Well... you'll get at least one of your favorite seasons!" } }, { "q": "Do you like activities?", "a": { "yes": "There are plenty of things to do in Iowa!", "no": "You'll be so busy having fun that you won't notice!" } }, { "q": "Do you like the party atmosphere?", "a": { "yes": "There's plenty of that inner-city feel in Des Moines, Ames, and Iowa City.", "no": "You can go roam the countryside if you want!" } }, { "q": "Do you like a quiet, rural atmosphere?", "a": { "yes": "Awesome. You can head 10-20 miles out of any city and get to a wide, free-flowing countryside.", "no": "Well... you can stay in the city then." } }
];
var numQuestion = -1, $questions = $('.questions'), $response = $('.response');
var loadNewQuestion = function() { $questions.text(questions[numQuestion].q); $response.html('').removeClass('open'); $('input').attr({ checked: false }); console.log(numQuestion, questions.length); if ( (numQuestion + 1) === questions.length ) { $('button').css('display', 'none'); console.log('last q'); }
};
$(document).ready(function() { numQuestion++; loadNewQuestion(); $('input').on('change', function() { var answer = $('input:checked').val(); $response.addClass('open'); $response.text(questions[numQuestion].a[answer]); }); $('#next').on('click', function() { numQuestion++; loadNewQuestion(); });
});
Developer | Joshua P. Larson |
Username | jplhomer |
Uploaded | July 23, 2022 |
Rating | 3.5 |
Size | 4,596 Kb |
Views | 48,576 |
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 |
Verge-Style Homepage Tiles | 5,147 Kb |
Responsive HTML Timeline | 3,137 Kb |
Seamless Scrolling Background | 2,535 Kb |
Fixed Nav HoverIntent Example | 4,444 Kb |
Displaying a Google Street View of your current location | 2,275 Kb |
Populate Native HTML Datalist with AJAX | 2,763 Kb |
Hey React | 3,959 Kb |
CSS-Only Art Direction | 4,086 Kb |
Animated Donut Chart | 3,808 Kb |
JS Geolocator | 2,653 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 canvas drawing | Aurer | 2,204 Kb |
Twitch TV | Natester13 | 4,488 Kb |
Scroll effect with text with help from Skrollr | Luxonglassing | 2,935 Kb |
Off Canvas | Mariamarica | 1,870 Kb |
Navcube | Wbarlow | 4,775 Kb |
Brian The CSS Bee | Jonitrythall | 3,922 Kb |
React Vote Component | Souporserious | 5,465 Kb |
Flip test | Madhes | 1,635 Kb |
Header Line Issue | Charlie-volpe | 1,768 Kb |
RAQuote | Naderk007 | 4,412 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!