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

              
                <h1>Demo of Creating jQuery Plugin—Image Slideshow</h1>

<ul id='slideshow'>
  <li><img src='http://unsplash.it/500/200?image=151' alt='Placeholder image'></li>
  <li><img src='http://unsplash.it/500/200?image=152' alt='Placeholder image'></li>
  <li><img src='http://unsplash.it/500/200?image=153' alt='Placeholder image'></li>
  <li><img src='http://unsplash.it/500/200?image=154' alt='Placeholder image'></li>
  <li><img src='http://unsplash.it/500/200?image=155' alt='Placeholder image'></li>
</ul>

<p><small>This is a demo by Makzan. Created for the <a href='https://gum.co/jquery101'>Beginning jQuery</a> course.</small></p>






              
            
!

CSS

              
                /* Slideshow controlling */

/* Theme A */
.theme-a.slideshow li {
  transition: all 0.35s ease-out;
}
.theme-a.slideshow li.ready-to-show {
  transform: translateX(100%);
  transition: none;
}
.theme-a.slideshow li.showing {
  transform: translateX(0);
}
.theme-a.slideshow li.after-show {
  transform: translateX(-100%);
}

/* Theme B */
.theme-b.slideshow li {
  transition: all 0.65s ease-out;
}
.theme-b.slideshow li.ready-to-show {
  transform: scale(.9);
  opacity: 0;
  transition: none;
}
.theme-b.slideshow li.showing {
  transform: scale(1);
  opacity: 1;
}
.theme-b.slideshow li.after-show {
  transform: scale(1.4);
  opacity: 0;
}

/* Slideshow layout style */
.slideshow {
  overflow: hidden;  
  width: 500px;
  height: 200px;
  position: relative;
}
ul.slideshow {
  margin: 0;
  padding: 0;
  list-style: none;
}
.slideshow li {
  position: absolute;  
}

/* Not related */
.slideshow {
  border: 3px solid BLACK;
  border-radius: 5px;
}

body {
  padding: 50px;
}
              
            
!

JS

              
                (function($) {
  $.fn.makeSlideshow = function(options) {
    // default settings
    var settings = $.extend({
      theme: 'theme-a',
      interval: 3000,
    }, options );
    
    var container = $(this);
    
    // apply theme
    container.removeClass().addClass('slideshow').addClass(settings.theme);
    
    // get all images
    var images = $(this).find('li');

    // make all images in `before` state
    images.addClass('ready-to-show');

    // current index default 0.
    var currentIndex = 0;

    // showing 1 image by default.
    images.eq(currentIndex).removeClass().addClass('showing');

    function nextSlide() {
      // move all existing `after` image to ready-to-show state.
      container.find('li.after-show').removeClass().addClass('ready-to-show');

      // find the current image and move it to after-show.
      images.eq(currentIndex).removeClass().addClass('after-show');

      // increase currentIndex by 1. Reset to 0 if the index exceeds count of images.
      currentIndex = (currentIndex + 1 ) % images.length;

      // move next image to current.
      images.eq(currentIndex).removeClass().addClass('showing');  
    }

    setInterval(nextSlide, settings.interval);  

    return this;
  };  
})(jQuery);

$('#slideshow').makeSlideshow({
  theme: 'theme-b',
  interval: 1500,
});

              
            
!
999px

Console