Pen Settings

HTML

CSS

CSS Base

Vendor Prefixing

Add External Stylesheets/Pens

Any URLs added here will be added as <link>s in order, and before the CSS in the editor. You can use the CSS from another Pen by using its URL and the proper URL extension.

+ 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="slider">
  <div><img src="https://source.unsplash.com/960x640/?nature" alt="Image 1"></div>
  <div><img src="https://source.unsplash.com/960x640/?travel" alt="Image 2"></div>
  <div><img src="https://source.unsplash.com/960x640/?city" alt="Image 3"></div>
  <div><img src="https://source.unsplash.com/960x640/?food" alt="Image 4"></div>
  <div><img src="https://source.unsplash.com/960x640/?animal" alt="Image 5"></div>
  <div><img src="https://source.unsplash.com/960x640/?architecture" alt="Image 6"></div>
</div>
              
            
!

CSS

              
                .slider {
  
  display: flex; /* 將 .slider 設為 flex container */
  justify-content: space-between; /* 水平置中 */
  align-items: center; /* 垂直置中 */
  flex-wrap: wrap;
}
.slider > div{
  width:32%;
  margin-bottom:20px;
}
.slider img{
  width:100%;
}
              
            
!

JS

              
                (function($){
  var windowWidth = $(window).width();
  var breakPoint = 768;
  var slider;

  // 載入 bxSlider
  function loadSlider() {
    slider = $('.slider').bxSlider();
  }

  // 移除 bxSlider
  function destroySlider() {
    if (slider !== undefined) {
      slider.destroySlider();
      slider = undefined;
    }
  }

  // 判斷視窗大小,決定是否載入 bxSlider
  function loadslider() {
    if (windowWidth <= breakPoint) {
      loadSlider();
    }
  }
  loadslider();

  // 視窗縮放時重新載入或移除 bxSlider
  $(window).resize(function() {
    var newWindowWidth = $(window).width();
    if (windowWidth <= breakPoint && newWindowWidth > breakPoint) {
      destroySlider();
    } else if (windowWidth > breakPoint && newWindowWidth <= breakPoint) {
      loadSlider();
    }
    windowWidth = newWindowWidth;
  });

})(jQuery);
              
            
!
999px

Console