cssAudio - Activefile-genericCSS - ActiveGeneric - ActiveHTML - ActiveImage - ActiveJS - ActiveSVG - ActiveText - Activefile-genericVideo - ActiveLovehtmlicon-new-collectionicon-personicon-teamlog-outoctocatpop-outspinnerstartv

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.

Quick-add: + add another resource

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.

Quick-add: + add another resource

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.

            
              <div id="desc">Click any star to spin it.</div>
<div id="scorebox">
  <span>Stars Spinning:</span>
  <span id="score">0/12</span>
</div>
<div id="stars"></div>

            
          
!
            
              body { background: url(http://www.svidget.com/images/assets/starrysky.jpg); }
object { border: 1px solid #4f4f4f; }

#desc { position: absolute; top: 5px; left: 5px; font-family: Arial; font-size: 20px; color: #f2f2f2; }
#scorebox { position: absolute; top: 5px; right: 5px; font-family: Arial; font-size: 20px; color: #f2f2f2; }
#score { font-weight: bold; }

#stars { position: absolute; top: 0px; left: 0px; bottom: 0px; right: 0px; }
            
          
!
            
              // note: requires version 0.3.3 or later of svidget.js
var starBgColor = '#f2d736';
var starBdColor = '#f2f2f2';
var starBdWidth = 8;
var starLocations = [
  [50, 130],
  [80, 550],
  [290, 360],
  [310, 100],
  [380, 420],
  [450, 80],
  [700, 40],
  [760, 420],
  [870, 120],
  [920, 470],
  [1000, 50],
  [1020, 280]
];
var starSizes = [200, 120, 80, 120, 200, 320, 80, 120, 100, 200, 200, 120];
var spinning = {};
var total = 0;

// load the widgets onto the page
for (var i = 0, j = 0; i < starLocations.length && j < starSizes.length; i++, j++) {
  var id = "star" + i;
  svidget.load("#stars",
    // widget options
    {
      id: id,
      url: "https://www.svidget.io/widgets/spinningstar.svg",
      width: starSizes[j],
      height: starSizes[j],
      style: "", // add css styling here
      crossdomain: true,
      // setting x and y serves as a shortcut to css positioning
      x: starLocations[i][0],
      y: starLocations[i][1],
    },
    // widget params for spinningstar widget
    // see for more info: http://www.svidget.com/examples/spinningstar
    {
      backgroundColor: starBgColor,
      borderWidth: starBdWidth,
      borderColor: starBdColor
    });
  total++;
}

svidget.onwidgetload(handleWidgetLoaded);

function handleWidgetLoaded(e) {
  // e.value is the ID of the widget that was just loaded
  var w = svidget.widget(e.value);
  // wire event handlers for the star widget's events
  w.event("spinStart").ontrigger(handleSpinStart);
  w.event("spinComplete").ontrigger(handleSpinComplete);
}

function handleSpinStart(e) {
  // get the widgetID, target is the eventDesc object, and parent is the WidgetReference
  var widgetID = e.target.parent().id();
  spinning[widgetID] = 1;
  updateCounter();
}

function handleSpinComplete(e) {
  // get the widgetID, target is the eventDesc object, and parent is the WidgetReference
  var widgetID = e.target.parent().id();
  spinning[widgetID] = 0;
  updateCounter();
}

function updateCounter() {
  var counter = getSpinningCount();
  svidget.dom.get("score").innerHTML = counter + "/" + total;
}

function getSpinningCount() {
  var counter = 0;
  for (var i in spinning) {
    counter += spinning[i];
  }
  return counter;
}
            
          
!
999px
Loading ..................

Console