HTML preprocessors can make writing HTML more powerful or convenient. For instance, Markdown is designed to be easier to write and read for text documents and you could write a loop in Pug.
In CodePen, whatever you write in the HTML editor is what goes within the <body>
tags in a basic HTML5 template. So you don't have access to higher-up elements like the <html>
tag. If you want to add classes there that can affect the whole document, this is the place to do it.
In CodePen, whatever you write in the HTML editor is what goes within the <body>
tags in a basic HTML5 template. If you need things in the <head>
of the document, put that code here.
The resource you are linking to is using the 'http' protocol, which may not work when the browser is using https.
CSS preprocessors help make authoring CSS easier. All of them offer things like variables and mixins to provide convenient abstractions.
It's a common practice to apply CSS to a page that styles elements such that they are consistent across all browsers. We offer two of the most popular choices: normalize.css and a reset. Or, choose Neither and nothing will be applied.
To get the best cross-browser support, it is a common practice to apply vendor prefixes to CSS properties and values that require them to work. For instance -webkit-
or -moz-
.
We offer two popular choices: Autoprefixer (which processes your CSS server-side) and -prefix-free (which applies prefixes via a script, client-side).
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.
You can apply CSS to your Pen from any stylesheet on the web. Just put a URL to it here and we'll apply it, in the order you have them, before the CSS in the Pen itself.
If the stylesheet you link to has the file extension of a preprocessor, we'll attempt to process it before applying.
You can also link to another Pen here, and we'll pull the CSS from that Pen and include it. If it's using a matching preprocessor, we'll combine the code before preprocessing, so you can use the linked Pen as a true dependency.
JavaScript preprocessors can help make authoring JavaScript easier and more convenient.
Babel includes JSX processing.
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.
You can apply a script from anywhere on the web to your Pen. Just put a URL to it here and we'll add it, in the order you have them, before the JavaScript in the Pen itself.
If the script you link to has the file extension of a preprocessor, we'll attempt to process it before applying.
You can also link to another Pen here, and we'll pull the JavaScript from that Pen and include it. If it's using a matching preprocessor, we'll combine the code before preprocessing, so you can use the linked Pen as a true dependency.
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.
Using packages here is powered by Skypack, which makes packages from npm not only available on a CDN, but prepares them for native JavaScript ES6 import
usage.
All packages are different, so refer to their docs for how they work.
If you're using React / ReactDOM, make sure to turn on Babel for the JSX processing.
If active, Pens will autosave every 30 seconds after being saved once.
If enabled, the preview panel updates automatically as you code. If disabled, use the "Run" button to update.
If enabled, your code will be formatted when you actively save your Pen. Note: your code becomes un-folded during formatting.
Visit your global Editor Settings.
<div class="app">
<h1>Central New Jersey Web Developers<br />Wheel of Topics</h1>
<button id="spin_button" onClick="startSpin();">Spin</button>
<div align="center" valign="center">
<canvas id='myCanvas' width='438' height='500'>
Canvas not supported, use another browser.
</canvas>
<button onClick="changeColours();">Spin Colors/Reset</button>
</div>
<p>Powered by Winwheel.js</p>
<p>Thank you to <a href="https://codepen.io/crowdcg">crowdcg</a></p>
body
{
background: #333366;
background-size: contain;
font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, Helvetica, Arial, sans-serif, "Apple Color Emoji", "Segoe UI Emoji", "Segoe UI Symbol"; //system font stack
}
.app {
background-color: rgba(255,255,255,0.8);;
border-radius: 10%;
margin: 0 auto;
max-width: 600px;
padding: 1rem;
text-align: center;
}
@media screen and (max-width: 600px) {
.app{
padding: 0;
}
}
/* Sets the background image for the wheel */
.the_wheel
{
background-position: center;
background-repeat: no-repeat;
}
/* Do some css reset on selected elements */
h1, p
{
margin: 0;
color: #333366;
}
/* Styles for the power selection controls */
table.power
{
background-color: #cccccc;
cursor: pointer;
border:1px solid #333333;
}
table.power th
{
background-color: white;
cursor: default;
}
td.pw1
{
background-color: #6fe8f0;
}
td.pw2
{
background-color: #86ef6f;
}
td.pw3
{
background-color: #ef6f6f;
}
/* Style applied to the spin button once a power has been selected */
.clickable
{
cursor: pointer;
}
/* Other misc styles */
.margin_bottom
{
margin-bottom: 5px;
}
button {
background: #ffcc33;
border: 2px solid black;
cursor: pointer;
font-size: 1rem;
font-weight: 700;
margin: 1rem;
padding: 1rem;
text-transform: uppercase;
}
.swal-modal {vertical-align:top;}
//kind of kludgy resizing for mobile
const mq = window.matchMedia( "(min-width: 600px)" );
if (mq.matches) {
// window width is at least 600px
//document.body.style.backgroundColor = "pink";
} else {
// window width is less than 600px
document.getElementById('myCanvas').width = 330;
document.getElementById('myCanvas').height = 330;
}
var theWheel = new Winwheel({
'canvasId' : 'myCanvas',
'numSegments' : 8,
'segments' :
[
{'fillStyle' : '#3366cc', 'text' : 'Javascript'},
{'fillStyle' : '#66cc66', 'text' : 'Web Security'},
{'fillStyle' : '#ff9966', 'text' : 'UI/UX'},
{'fillStyle' : '#cc3366', 'text' : 'Data Modeling'},
{'fillStyle' : '#ff9999', 'text' : 'CSS'},
{'fillStyle' : '#993366', 'text' : 'Tech News'},
{'fillStyle' : '#3399ff', 'text' : 'Storytelling'},
{'fillStyle' : '#663399', 'text' : 'Accessibility'}
],
'fillStyle' : '#e770df',
'textFontFamily' : 'Georgia',
'lineWidth' : 3,
// Specify the animation to use.
animation: {
type: "spinToStop",
duration: 3, // Duration in seconds.
spins: 4, // Number of complete spins.
callbackFinished: alertPrize
}
});
// Vars used by the code in this page to do power controls.
var wheelPower = 0;
var wheelSpinning = false;
// -------------------------------------------------------
// Function to handle the onClick on the power buttons.
// -------------------------------------------------------
function powerSelected(powerLevel) {
// Ensure that power can't be changed while wheel is spinning.
if (wheelSpinning == false) {
document.getElementById("spin_button").className = "clickable";
}
}
// -------------------------------------------------------
// Click handler for spin button.
// -------------------------------------------------------
function startSpin() {
//alert('startspin');
// Ensure that spinning can't be clicked again while already running.
if (wheelSpinning == false) {
// Based on the power level selected adjust the number of spins for the wheel, the more times is has
// to rotate with the duration of the animation the quicker the wheel spins.
if (wheelPower == 1) {
theWheel.animation.spins = 3;
} else if (wheelPower == 2) {
theWheel.animation.spins = 8;
} else if (wheelPower == 3) {
theWheel.animation.spins = 15;
}
// Disable the spin button so can't click again while wheel is spinning.
document.getElementById("spin_button").src = "spin_off.png";
document.getElementById("spin_button").className = "";
// Begin the spin animation by calling startAnimation on the wheel object.
theWheel.startAnimation();
// Set to true so that power can't be changed and spin button re-enabled during
// the current animation. The user will have to reset before spinning again.
wheelSpinning = true;
}
}
// -------------------------------------------------------
// Function for reset button.
// -------------------------------------------------------
function resetWheel() {
theWheel.stopAnimation(false); // Stop the animation, false as param so does not call callback function.
theWheel.rotationAngle = 0; // Re-set the wheel angle to 0 degrees.
theWheel.draw(); // Call draw to render changes to the wheel.
document.getElementById("pw1").className = ""; // Remove all colours from the power level indicators.
document.getElementById("pw2").className = "";
document.getElementById("pw3").className = "";
wheelSpinning = false; // Reset to false to power buttons and spin can be clicked again.
}
// -------------------------------------------------------
// Called when the spin animation has finished by the callback feature of the wheel because I specified callback in the parameters
// note the indicated segment is passed in as a parmeter as 99% of the time you will want to know this to inform the user of their prize.
// -------------------------------------------------------
function alertPrize(indicatedSegment) {
// Do basic alert of the segment text. You would probably want to do something more interesting with this information.
//alert("Your topic is " + indicatedSegment.text);
swal("Your topic is " + indicatedSegment.text, "", "success");
}
function changeColours()
{
// Change colours as desired by accessing the segment via the segments array
// of the wheel object (note first array position is 1 not 0).
var temp = theWheel.segments[1].fillStyle;
var temp2 = theWheel.segments[5].fillStyle;
theWheel.segments[1].fillStyle = theWheel.segments[2].fillStyle;
theWheel.segments[2].fillStyle = theWheel.segments[3].fillStyle;
theWheel.segments[3].fillStyle = theWheel.segments[4].fillStyle;
theWheel.segments[5].fillStyle = theWheel.segments[6].fillStyle;
theWheel.segments[6].fillStyle = theWheel.segments[7].fillStyle;
theWheel.segments[7].fillStyle = theWheel.segments[8].fillStyle;
theWheel.segments[8].fillStyle = temp2;
theWheel.segments[4].fillStyle = temp;
// The draw method of the wheel object must be called
// in order for the changes to be rendered.
theWheel.draw();
wheelSpinning = false;
}
Also see: Tab Triggers