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 id="controls">
  <h2>Slideshow Options</h2>
  <p><label>Delay (seconds):</label>
  <Select id="interval">
    <option value="1000">1</option>
    <option value="2000">2</option>
    <option value="3000">3</option>
    <option value="4000">4</option>
    <option value="5000" selected>5</option>
    <option value="6000">6</option>
    <option value="7000">7</option>
    <option value="8000">8</option>
    <option value="9000">9</option>
    <option value="10000">10</option>
  <label for"forward">Forward</label><input name="order" value="forward" type="radio" checked />
  <label for"reverse">Reverse</label><input name="order" value="reverse" type="radio" />
  <label for"shuffle">Shuffle</label><input name="order" value="shuffle" type="radio" />
  <label for"random">Random</label><input name="order" value="random" type="radio" /> 
  Effect: <label for"slide">Slide</label><input type="radio" name="effect" value="slide">
          <label for"slide">Fade</label><input type="radio" name="effect" value="fade" checked>
     <label for"transitionTime">Transition Time (ms)</label> 
     <Select id="transitionTime">
        <option value="500">500</option>
        <option value="1000" selected>1000</option>
        <option value="1500">1500</option>
        <option value="2000">2000</option>
       <option value="2500">2500</option>
       <option value="3000">3000</option>
  <button id="start">Start Slideshow</button>&nbsp;&nbsp;
  <button id="pause">Pause Slideshow</button>&nbsp;&nbsp;
  <button id="stop">Stop Slideshow</button>
<div id="slideshow">
    <img src="" alt="mustang.jpg"><br>
    A newer Mustang.
    <img src="" alt="camaro.jpg"><br>
    A modern Camaro.
    <img src="" alt="classic.jpg"><br>
    An oldie but a goodie!
    <img src="" alt="classic2.jpg"><br>
    More old cars.
    <img src="" alt="video_game_car.jpg"><br>
    A good rendering of a classic race car.
<br />
<br />
<br />
<br />
<br />
<br />
<br />
<br />
<br />
<hr />
<p>If you find this demo useful, please consider <a href="" target="_blank">donating $1 dollar</a> for a coffee (secure PayPal link) or purchasing one of my songs from <a href="" target="_blank"></a> or <a href="" target="_blank"></a> for only 0.99 cents each.</p>
<p>Rob uses and recommends <a href="" target="_blank">MochaHost</a>, which provides Web Hosting for as low as $1.95 per month, as well as unlimited emails and disk space!</p>ch provides Web Hosting for as low as $1.95 per month, as well as unlimited emails and disk space!</p>
              body {
   background-color: gray;
   font-family: Arial, sans-serif;

#controls {
  border: 1px solid black;
  text-align: center;
  margin:0 auto;
  padding-bottom: 10px;
  z-index: 1;

#slideshow { 
    position: relative; 
    width: 300px; 
    height: 510px; 
    padding: 10px; 
    //top: 150px;

#slideshow > div { 
    position: absolute; 
    text-align: center;
    overflow: visible;
    display: none;

#slideshow > div > img {
    border: 2px solid white;
    box-shadow: 0 0 20px white; 
     = function( parent ) {
    parent = $( parent ? this.parent() : window );
        "position": "absolute",
        "top": (((parent.height() - this.outerHeight()) / 2) + parent.scrollTop() + "px"),
        "left": (((parent.width() - this.outerWidth()) / 2) + parent.scrollLeft() + "px")
    return this;

jQuery.fn.setDivSize = function(extraHeight, extraWidth) {
  var img = new Image();
  img.src = this.children('img').attr('src'); 
  this.height(img.height + extraHeight)
      .width( img.width  + extraHeight);
  return this;

$(function() {  
  var timerHandle, 
      slideshowDiv = $('#slideshow'),
      divClone     = slideshowDiv.clone(),
      noOfSlides   = slideshowDiv.children('div').length;
  $('#start').click(function(evt) {
    var delay          = parseInt( $("#interval option:selected").val() ),
        order          = $('input[name=order]:checked').val(),
        effect         = $('input[name=effect]:checked').val(),
        transitionTime = parseInt( $("#transitionTime option:selected").val() );
    switch ( order ) {
      case 'random':
        var divIndex = Math.floor(Math.random() * noOfSlides);
        $('#slideshow > div').eq(divIndex).prependTo( $('#slideshow') );
      case 'reverse':
        var slides = $('#slideshow > div');
      case 'shuffle':
        var slides = $('#slideshow > div');
        while (slides.length) {
          $('#slideshow').append(slides.splice(Math.floor(Math.random() * slides.length), 1)[0]);
    //show the first slide immediately
    $('#slideshow > div:first')
      .setDivSize(30, 40)
      [( effect == 'fade' ? 'fadeIn' : 'slideDown')](transitionTime);

    play(order, noOfSlides, delay, effect, transitionTime);
  $('#pause').click(function() {
    if (!timerHandle) return;
    with ( $(this) ) {
      text( hasClass('paused') 
            ? 'Continue Slideshow' 
            : 'Pause Slideshow' );
  $('#stop').click(function() {
    $( '#pause' ).removeClass('paused').text('Pause Slideshow');
    timerHandle = 0;
  function play(order, noOfSlides, delay, effect, transitionTime) {
    timerHandle = setInterval(function() { 
      if ( ! $('#pause').hasClass('paused') ) {
        if ( order === 'random' ) {
          var divIndex = Math.floor(Math.random() * (noOfSlides - 1)) + 1;
          //set the next() slide
          $('#slideshow > div')
            .insertAfter( $('#slideshow > div:first') );
        $('#slideshow > div:first')
          [( effect == 'fade' ? 'fadeOut' : 'slideUp')](transitionTime)
          [( effect == 'fade' ? 'fadeIn' : 'slideDown')](transitionTime)
    },  delay);
🕑 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.