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

              
                <!-- 
open in mobile device 
or simulator in Dev Tools
-->
<div class="layer">
  <h3>layer</h3>
  <div class="result">Event.type will show here</div>
</div>
              
            
!

CSS

              
                .layer {
  background: #f1f1f1;
  box-sizing: border-box;
  padding: .65rem;
  min-height: 200px;
}
              
            
!

JS

              
                (function() {
  // tiny mixin
  function extend(obj, extension) {
    for (var key in extension) {
      obj[key] = extension[key];
    }
  }

  // tiny pub/sub
  var Events = function() {
    this.map = {};
  };

  Events.prototype = {
    publish: function(eventname, args) {
      if (this.map[eventname]) {
        this.map[eventname].forEach(function(fn) {
          fn.apply(this, args);
        });
      }
    },
    subscribe: function(eventname, callback) {
      if (this.map[eventname]) {
        this.map[eventname].push(callback);
      } else {
        this.map[eventname] = [callback];
      }
    }
  };

  function Swipe(elem) {
    Events.call(this);
    this.sp = {};
    this.ep = {};
    this.nm = true;
    this.bindSwipe(elem);
  }

  Swipe.prototype = {
    bindSwipe: function(elem) {
      elem.addEventListener("touchstart", this._touchstart.bind(this));
      elem.addEventListener("touchmove", this._touchmove.bind(this));
      elem.addEventListener("touchend", this._touchend.bind(this));
    },

    _touchstart: function(e) {
      this.nm = true;
      this.sp.x = e.touches[0].pageX;
      this.sp.y = e.touches[0].pageY;
    },

    _touchmove: function(e) {
      this.nm = false;
      this.ep.x = e.touches[0].pageX;
      this.ep.y = e.touches[0].pageY;
    },

    _touchend: function(e) {
      var x = this.ep.x - this.sp.x,
        xr = Math.abs(x),
        y = this.ep.y - this.sp.y,
        yr = Math.abs(y);

      if (this.nm) {
        this.publish("tap");
      } else {
        if (Math.max(xr, yr) > 20) {
          this.publish(
            xr > yr
              ? x < 0 ? "swipe left" : "swipe right"
              : y < 0 ? "swipe up" : "swipe down"
          );
        }
      }
      this.nm = true;
    }
  };
  
  extend(Swipe.prototype, Events.prototype);
  
  var layer = document.querySelector('.layer')
    , result = document.querySelector('.result');
  
  var s = new Swipe(layer);
  
  s.subscribe('swipe left', function (e) {
    result.innerHTML = 'swipe left';
  });
  
  s.subscribe('swipe right', function (e) {
    result.innerHTML = 'swipe right';
  });
  
  s.subscribe('swipe up', function (e) {
    result.innerHTML = 'swipe up';
  });
  
  s.subscribe('swipe down', function (e) {
    result.innerHTML = 'swipe down';
  });
  
  s.subscribe('tap', function (e) {
    result.innerHTML = 'tap';
  });
})();

              
            
!
999px

Console