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 id="sg" class="gallery">
  <div>
    <section class="item">
      <h1>Number #1</h1>
      <p>Lorem ipsum dolor sin</p>
    </section>
    <section class="item">
      <h1>Number #2</h1>
      <p>Lorem ipsum dolor sin</p>
    </section>
    <section class="item">
      <h1>Number #3</h1>
      <p>Lorem ipsum dolor sin</p>
    </section>
    <section class="item">
      <h1>Number #4</h1>
      <p>Lorem ipsum dolor sin</p>
    </section>
    <section class="item">
      <h1>Number #5</h1>
      <p>Lorem ipsum dolor sin</p>
    </section>
  </div>
</div>

<p><button onclick="bs.cycle()">start</button></p>
              
            
!

CSS

              
                // configure here the widget dimensions
@w: 400px;
@h: 180px;
@s: 20px;

.gallery {
  position: relative;
  overflow: hidden;
  -moz-box-sizing: border-box;
  box-sizing: border-box;
  width: @w;
  height: @h;
  padding: @s;
  box-shadow: 0 0 1px #aaa;
  > div {
    position: absolute;
    top: 0;
    padding-top: @s;
    .item {
      display: inline-block;
      width: (@w - 2 * @s);
      height: (@h - 2 * @s);
      background: #eee;
      text-align: center;
      margin-bottom: @s;
      h1 {
        font-size: 16px;
      }
    }
  }
}
              
            
!

JS

              
                /**
 * IntervalController Mixin
 * Provides methods to start, stop and resume
 * a setInterval functionality
 */
var IntervalController = new Class({
  _started: false,
  _handler: null,
  _callback: null,
  _interval: null,
  startInterval: function(callback, interval) {
    this._callback = callback;
    this._interval = interval;
    this._handler = setInterval(callback, interval);
    this._started = true;
  },
  stopInterval: function() {
    if(this._handler === null) {
      console.log("nothing to stop");
    }
    else {
      clearInterval(this._handler);
      this._handler = null;
    }
  },
  resumeInterval: function() {
    if(!this._started) {
      console.log("not yet started");
    }
    else if(this._handler !== null) {
      console.log("already running");
    }
    else {
      this._handler = setInterval(this._callback, this._interval);  
    }
  }
});

/**
 * Bounce Showcase Class
 * Creates a bounce showcase ui widget starting from
 * an html structured this way:
 *
 * #container
 *   div
 *     .item
 *     .item
 *     ...
 *
 * Options:
 * - interval: interval step
 * - pause_onmouseover: pause animation on container mouseover
 * - reset_loop_cnt: after how many animation the widget is reset
 *
 * The infinite loop is created cloning the items and appending them at the bottom of the rail.
 * After a certain number of animations the widget should be reset in order to avoid rail pollution
 */
var BounceShowcase = new Class({
  Implements: [Options, IntervalController],
  options: {
    interval: 2000,
    pause_onmouseover: true,
    reset_loop_cnt: 20
  },
  initialize: function(el, options) {
    this._container = $(el);
    this._rail = this._container.getChildren('div')[0];
    this._or_items = this._rail.getChildren('.item');
    this._items = this._rail.getChildren('.item');
    this._step = this._container.getStyle('height').toInt() - this._container.getStyle('padding-bottom').toInt();
    this._fx = new Fx.Tween(this._rail, {
      property: 'top',
      transition: 'bounce:out'
    });
    this._on_stage = 0;
    this._loop_cnt = 0;
    
    this.setOptions(options); 
    var self = this;
    if(this.options.pause_onmouseover) {
      this._container.addEvents({
        'mouseover': function() {
          self.stopInterval();
        },
        'mouseleave': function() {
          self.resumeInterval();
        }
      });
    }
  },
  _setOnStage: function(index) {
    this._fx.start(-index * this._step).chain(function() {
      if(index > 0) {
        var clone = this._items[index - 1].clone();
        clone.inject(this._rail, 'bottom');
      }
      if(index == this._items.length - 1) {
        this._items = this._rail.getChildren('.item'); 
      }
      this._loop_cnt++;
      if(this._loop_cnt >= this.options.reset_loop_cnt) {
        this.reset();
      }
    }.bind(this)); 
  },
  cycle: function() {
    var self = this;
    this.startInterval(function() {
      self._setOnStage(++self._on_stage);
    }, this.options.interval);
  },
  reset: function() {
    this.stopInterval();
    this._rail.empty();
    this._or_items.each(function(item) {
      item.inject(this._rail);
    }.bind(this)); 
    this._fx.set(0);
    this._on_stage = 0;
    this._loop_cnt = 0;
    this.cycle();
  }
});

var bs = new BounceShowcase('sg', {
  pause_onmouseover: true,
  interval: 2500,
  reset_loop_cnt: 10
});
              
            
!
999px

Console