Pen Settings

HTML

CSS

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

JavaScript

Babel is required to process package imports. If you need a different preprocessor remove all packages first.

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

Behavior

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.

Format on Save

If enabled, your code will be formatted when you actively save your Pen. Note: your code becomes un-folded during formatting.

Editor Settings

Code Indentation

Want to change your Syntax Highlighting theme, Fonts and more?

Visit your global Editor Settings.

HTML

              
                <div class="row">
  <div class="columns">
    <div id="names"></div>
  </div>
</div>

<div class="row">
  <div class="columns">
    <hr />
    <a class="button" id="chooseWinner" class="clear-fix thang chooseWinner">Choose Winner</a>

    <div id="myModal" class="reveal-modal" data-reveal aria-labelledby="modalTitle" aria-hidden="true" role="dialog">
      <h2 id="modalTitle">Winner!</h2>
      <div class="win-gif"></div>
      <h1 class="winner"></h1>
      <p class="winner-id"></p>
      <a class="close-reveal-modal" aria-label="Close">&#215;</a>
      <a id="notPresent" class="button">Not Here?</a>
    </div>
  </div>
</div>



              
            
!

CSS

              
                #names {}
ul {}

li {
  list-style:none;
  float:left;  
  display:inline;
  padding: 0;
}

li:after {
  content: "\a0\2022\a0";
  display:inline;
  font-weight:bold;
  padding: 0 10px;

}

.highlight {
  background:#006a4d;
  border-radius:3px;
  color:#fff;
}

.contestant {
  transition: 0.4s;
	transform-style: preserve-3d;
	position: relative;
  transform: rotateX(0deg);
  padding:3px
}

.contestant.flip {
  transform: rotateX(360deg)
}

.win-gif {
  margin:0 auto;
  width:200px;
  height: 200px;
  overflow:hidden;
  border-radius:500px;
  background-image: url(http://gifsec.com/wp-content/uploads/GIF/2014/12/Winner-GIF-2015.gif);
  background-size: cover;
  background-position: center; 
}

#myModal {
  max-width:30%;
  text-align:center;
}

.winner-id {
  color:#bbb;
}
              
            
!

JS

              
                var names = [
  {'id' : '456645', 'name': 'Tora Sauve'},
  {'id' : '123123', 'name': 'Toshiko Pawlowicz'},
  {'id' : '356545', 'name': 'Valeri Watchman'},
  {'id' : '374345', 'name': 'Vanesa Tift'},
  {'id' : '879097', 'name': 'Veronique Prado'},
  {'id' : '465464', 'name': 'Veta Maes'},
  {'id' : '786867', 'name': 'Wilhelmina Goguen'},
  {'id' : '345345', 'name': 'William Mahar'},
  {'id' : '789789', 'name': 'Winifred Langdon'},
  {'id' : '234234', 'name': 'Yuki Boerner'},
  {'id' : '387645', 'name': 'Joe Smith'}
]

var deferred = $.Deferred(),
    fanfare = 'http://www.ringelkater.de/Sounds/2geraeusche_gegenst/fanfare10.wav',
    drumrollClip = 'http://cd.textfiles.com/cdaction/cdaction05a/LORDS2/FILES/FF_BATL.WAV'

/*
 * Render names to the dom
 */
function render() {
  $('#names').empty();
  
  var ul = $('<ul>').appendTo('#names');

  $(names).each(function(index, item) {
    var l=$(document.createElement('li'));
    var s=$(document.createElement('span'));

    ul.append(
        l.append(
          s.attr('id', 'contestant' + index).addClass('contestant').text(item['name'])
        )
    );
  });
}

/*
 * Play an audio clip
 */
function playAudio(audioClip) {
  var audio = new Audio(audioClip);
  audio.play();
}

/*
 * Show modal with winner info
 */
function alertWinner(winner) {
  playAudio(fanfare)
  
  $('#myModal').foundation('reveal', 'open');
  $('.winner').text(winner['name']);
  $('.winner-id').text(winner['id']);  
}

/*
 * Rotate through names
 */
function roullette() {
  
  playAudio(drumrollClip)
  
  var promise = $.Deferred();
  (function myLoop (i) {
    setTimeout(function () {
      var randomContestant = Math.floor(Math.random() * (names.length - 1));
      
      $("#contestant" + randomContestant).each(function(s,x){
        $(x).addClass("highlight flip"); // add class
        setTimeout(function(){
          $(x).removeClass("highlight flip");
          // loop is really done now if i is zero
          if (i === 0) {
            promise.resolve( randomContestant );    
          }
        }, 250)
      })
     
      if (--i)  myLoop(i); // decrement i and call myLoop again if i > 0
    }, 200)
  })(14); //14
  return promise;
}

/*
 * Choose a winner
 */
function chooseWinner(closeModal) {
  
  if (closeModal) {
    $('#myModal').foundation('reveal', 'close');
  }
  
  render();
  
  roullette().then(function(winnerId) {
    $("#contestant" + winnerId).addClass('highlight flip');
    alertWinner( names[winnerId] );
  });
}

/*
 * Find and remove contestant from array based on name
 */
function findAndRemove(value) {
  _.remove(names, {
    id: value
  });
}

/*
 * click choose winner
 */
$('#chooseWinner').on('click', function(){
    chooseWinner();
});

/*
 * click non present
 */
$('#notPresent').on('click', function(){
  var winnerId = $('.winner-id').text();
  findAndRemove(winnerId);
  chooseWinner(true);
});

/*
 * Render names on page load
 */
$(document).ready(function(){
  render()
});

/*
 * Call foundation
 */
$(document).foundation();

              
            
!
999px

Console