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 is required to process package imports. If you need a different preprocessor remove all packages first.

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

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

              
                <header>
  <h1>Click and drag to scroll!</h1>
  <p class="belowHeader">(The jQuery way)</p>
</header>

<div class="section dark">
  <div class="wrapper">
    <h2>Setting our variables</h2>
    <div class="code">
      var curXPos = 0, curYPos = 0, curDown = false;
    </div>
  </div>
</div>

<div class="section">
  <div class="wrapper">
    <h2>Mouse down event</h2>
    <div class="code"> $(window).mousedown(function(m){
    curDown = true;
    curYPos = m.pageY;
    curXPos = m.pageX;
});
    </div>
  </div>
</div>

<div class="section dark">
  <div class="wrapper">
    <h2>Mouse up event</h2>
    <div class="code">
$(window).mouseup(function(){
    curDown = false;
});
    </div>
  </div>
</div>

<div class="section">
  <div class="wrapper">
    <h2>Mouse move event</h2>
    <div class="code">
  $(window).mousemove(function(m){
    if(curDown === true){
     $(window).scrollTop($(window).scrollTop() + (curYPos - m.pageY)); 
     $(window).scrollLeft($(window).scrollLeft() + (curXPos - m.pageX));
    }
});
    </div>
  </div>
</div>
              
            
!

CSS

              
                * {
  margin: 0;
  padding: 0;
  border: 0;
  outline: none;
  font-weight: 200;
  -webkit-font-smoothing: antialiased;
  font-family: segoe ui, helvetica neue, helvetica, arial, sans-serif;
  -webkit-user-select: none;
  -moz-user-select: moz-none;
  -ms-user-select: none;
  user-select: none;
}

/* Defaults */
body {
  font-size: 16px;
}

p, a, span {
  font-size: 90%;
  color: #666;
  liine-height: 20px;
}

.wrapper {
  width: 540px;
  margin: 0px auto;
}

/* Header */
header {
  padding: 120px 0px 120px 0px;
}

header h1 {
  font-size: 220%;
  color: #444;
  text-align: center;
}

header p {
  text-align: center;
}

/* Section */
.section {
  padding: 40px 0px 40px 0px;
}

.section.dark {
  background: #dedede;
}

.section h2 {
  color: #444;
  padding-bottom: 20px;
}

/* Code */
.code {
  padding: 20px;
  background: #dedede;
  color: #666;
}

.section.dark .code {
  background: #ccc;
}
              
            
!

JS

              
                $(function(){
  var curDown = false,
      curYPos = 0,
      curXPos = 0;
  
  $(window).mousemove(function(m){
    if(curDown){
      window.scrollBy(curXPos - m.pageX, curYPos - m.pageY)
    }
  });
  
  $(window).mousedown(function(m){
    curYPos = m.pageY;
    curXPos = m.pageX;
    curDown = true;
  });
  
  $(window).mouseup(function(){
    curDown = false;
  });
})
              
            
!
999px

Console