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.

            
              <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; 
}


            
          
!
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