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 ng-app='scrollApp'>
  <div ng-controller='AppCtrl'>
    <div scroll>
      <table data-anchor>
        <tr>
          <td>
            <div style='width: 5000px;'>
              {{ test }}
              <br />
              <br />
              <br />
              <br />
              <br />
              <br />
              <br />
              <br />
            </div>
          </td>
        </tr>
      </table>
    </div>

    <div scroll>
     <div data-anchor>
      {{ test }}
      <br />
      <br />
      <br />
      <br />
      </div>
    </div>


    <textarea ng-model='test'></textarea>
  </div>
</div>
              
            
!

CSS

              
                .div2 {
  background-color: #a00000;
  color: white;
  padding: 20px;
}

textarea {
  float: left;
  width: 100%;
}
              
            
!

JS

              
                angular.module('scrollApp', [])

.controller('AppCtrl', ['$scope', function($scope) {
  $scope.test = "hello";
}])

.directive('scroll', [function() {
  return {
    link: function(scope, element, attrs) {
      // ng-repeat delays the actual width of the element.
      // this listens for the change and updates the scroll bar
      function widthListener() {
        if (anchor.width() != lastWidth)
          updateScroll();
      }

      function updateScroll() {
        // for whatever reason this gradually takes away 1 pixel when it sets the width.
        $div2.width(anchor.width() + 1);

        // make the scroll bars the same width
        $div1.width($div2.width());

        // sync the real scrollbar with the virtual one.
        $wrapper1.scroll(function(){
          $wrapper2.scrollLeft($wrapper1.scrollLeft());
        });

        // sync the virtual scrollbar with the real one.
        $wrapper2.scroll(function(){
          $wrapper1.scrollLeft($wrapper2.scrollLeft());
        });
      }

      var anchor = element.find('[data-anchor]'),
          lastWidth = anchor.width(),
          listener;

      // so that when you go to a new link it stops listening
      element.on('remove', function() {
        clearInterval(listener);
      });

      // creates the top virtual scrollbar
      element.wrapInner("<div class='div2' />");
      element.wrapInner("<div class='wrapper2' />");

      // contains the element with a real scrollbar
      element.prepend("<div class='wrapper1'><div class='div1'></div></div>");

      var $wrapper1 = element.find('.wrapper1'),
          $div1 = element.find('.div1'),
          $wrapper2 = element.find('.wrapper2'),
          $div2 = element.find('.div2')

      // force our virtual scrollbar to work the way we want.
      $wrapper1.css({
        width: "100%",
        border: "none 0px rgba(0, 0, 0, 0)",
        overflowX: "scroll",
        overflowY: "hidden",
        height: "20px",
      });

      $div1.css({
        height: "20px",
      });

      $wrapper2.css({
        width: "100%",
        overflowX: "scroll",
      });

      listener = setInterval(function() {
        widthListener();
      }, 650);

      updateScroll();
    }
  }
}]);
              
            
!
999px

Console