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 includes JSX processing.

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

Packages

Add Packages

Search for and use JavaScript packages from npm here. By selecting a package, an import statement will be added to the top of the JavaScript editor for this package.

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="column">

<div class="lodge_slider" id="slider-1">
  
  <nav class="lodge_slider__nav">
    <ul>
      <a href="#slider-1__slide-1">Slide 1</a>
      <a href="#slider-1__slide-2">Slide 2</a>
      <a href="#slider-1__slide-3">Slide 3</a>
    </ul>
  </nav>
  
  <div class="lodge_slider__slider">
    
    <div class="lodge_slider__slide" id="slider-1__slide-1">
      <img src="https://s3-us-west-2.amazonaws.com/s.cdpn.io/3/owl1.jpg">
    </div>
    
    <div class="lodge_slider__slide" id="slider-1__slide-2">
      <img src="https://s3-us-west-2.amazonaws.com/s.cdpn.io/3/owl3.jpg">
    </div>
    
    <div class="lodge_slider__slide" id="slider-1__slide-3">
      <img src="https://s3-us-west-2.amazonaws.com/s.cdpn.io/3/usa.png">
    </div>
    
  </div>
  
</div>
  
</div>
              
            
!

CSS

              
                .lodge_slider {
  /* hide slides outside of view */
  overflow: hidden;
}

.lodge_slider__slide {
  float: left;
  width: 100%;
}

.lodge_slider__slide img {
  max-width: 100%;
  display: block;
}

.lodge_slider__slider {
  /* for animation */
  position: relative;
}





* {
  box-sizing: border-box;
}
.column {
  width: 35%;
  margin: 0 auto;
}
              
            
!

JS

              
                // Plugin framework from http://starter.pixelgraphics.us/

// Best practice: ensure $ is safe
(function($) {
  
  // Extending jQuery here just because it depends on it so might as well.
  $.lodgeSlider = function(el, options) {
    
    // To avoid scope issues, use 'base' instead of 'this'
    // to reference this class from internal events and functions.
    var base = this;
    
    // Access to jQuery and DOM versions of element
    base.$el = $(el);
    base.el = el;
    
    // Natural width at start
    base.baseWidth = base.$el.width();
    
    // Add a reverse reference to the DOM object
    base.$el.data("lodgeSlider", base);
    
    // Commonly referenced elements
    base.slider = base.$el.find(".lodge_slider__slider");
    base.allSlides = base.$el.find(".lodge_slider__slide");
    base.allNavLinks = base.$el.find(".lodge_slider__nav a");
    
    
    base.init = function() {
      base.options = $.extend({},$.lodgeSlider.defaultOptions, options);
      
      // Set slides to fixed size
      base.allSlides.css("width", base.baseWidth);
      
      // Count slides and make slider as wide as it needs to be. +1 to account for bad pixel rounding.
      var numSlides = base.findNumSlides();
      base.slider.css("width", numSlides*100+1 + "%");
      
      base.bindUI();
    };
    
    base.bindUI = function() {
      base.allNavLinks.on("click", function(event) {
        
        var id = this.hash;
        base.changeSlide(id);
        
        // Stop browser from going to #hash link
        event.preventDefault();
      });
    };
    
    base.findNumSlides = function() {
      return base.allNavLinks.length;
    };
    
    base.changeSlide = function(id) {
      var pos = $(id).index();
      var slideTo = pos * base.baseWidth;
      base.slider.animate({
        "left": -slideTo + "px"
      }, base.options.speed);
    };
    
    // Run initializer
    base.init();
    
  };
  
  $.lodgeSlider.defaultOptions = {
    "speed": 2000
  };
  
  $.fn.lodgeSlider = function(options){
    return this.each(function(){
      (new $.lodgeSlider(this, options));
    });
  };
    
})(jQuery);


// Kick it off!
$("#slider-1").lodgeSlider({
  "speed": 100
});


// Things could do
/*
- Make CSS do the moving instead of JS
- Fix rounding error
- Auto create the navigation
- Make sure to test multiple sliders
- Allow linking to slides from hash
- Touch support (slide to slides)
- API for adding slides
- API for changing slides
- Media features like expanding images or auto-playing/stopping video
- Theme examples
- Reset on width change
*/
              
            
!
999px

Console