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='slideShow'></div>
              
            
!

CSS

              
                .active img {
  border: 1px solid black;
}

.slide img {
  height: 50px;
}

.mainImage img {
  height: 150px;
}
              
            
!

JS

              
                var slideModelFactory = function(text, active) {
  // id is not observable
  var slide = {
    id: _.uniqueId('slide_')
  };
  return mobx.extendObservable(slide, {
    // observable fields
    active: active || false,
    imageText: text,
    // computed
    get imageMain() {
      return 'https://placeholdit.imgix.net/~text?txtsize=33&txt=' + slide.imageText + '&w=350&h=150';
    },
    get imageThumb() {
      return 'https://placeholdit.imgix.net/~text?txtsize=22&txt=' + slide.imageText + '&w=400&h=50';
    }
  });
};

var slideShowModelFactory = function(slides) {
  return mobx.observable({
    // observable
    slides: _.map(slides, function(slide) {
      return slideModelFactory(slide.text, slide.active);
    }),
    // computed
    get activeSlide() {
      return _.find(this.slides, {
        'active': true
      });
    },
    // action
    setActiveSlide: mobx.action('set active slide', function(slideId) {
      // deactivate the current slide 
      this.activeSlide.active = false;
      // set the next slide as active
      _.find(this.slides, {id: slideId}).active = true;
    })
  });
};

var slideShowModel = slideShowModelFactory([{
  text: 'Heloo!',
  active: true
}, {
  text: 'Cool!'
}, {
  text: 'MobX!'
}]);

var $slideShowContainer = $('#slideShow');

// add event handling
$slideShowContainer.on('click', '.slide', function() {
  slideShowModel.setActiveSlide($(this).data('slideId'));
});

mobx.autorun(function() {
  var html = '<div class="mainImage"><img src="' + slideShowModel.activeSlide.imageMain + '"/></div>';
  html += '<div id="slides">';
  _.forEach(slideShowModel.slides, function(slide) {
    html += '<div class="slide ' + (slide.active ? ' active' : '') + '" data-slide-id="' + slide.id + '">';
    html += '<img src="' + slide.imageThumb + '"/>';
    html += '</div>';
  });
  html += '</div>';
  $slideShowContainer.html(html);
});
              
            
!
999px

Console