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

              
                <article id="example">A scrollbar is a graphical control element with which continuous text, pictures or anything else can be scrolled including time in video applications, i.e., viewed even if it does not fit into the space in a computer display, window, or viewport. It was also known as a handle in the very first GUIs.

Scrollbars are present in a wide range of electronic devices including computers, graphing calculators, mobile phones, and portable media players. They usually appear on one or two sides of the viewing area as long rectangular areas containing a bar (or thumb) that can be dragged along a trough (or track) to move the body of the document as well as two arrows on either end for precise adjustments. The "thumb" has different names in different environments: on the Macintosh it is called a "scroller";[1] on the Java platform it is called "thumb" or "knob"; Microsoft's .NET documentation refers to it as "scroll box" or "scroll thumb"; in other environments it is called "elevator", "quint", "puck", "wiper" or "grip". Additional functions may be found, such as zooming in/out or various application-specific tools. Depending on the graphical user interface, the size of the thumb can be fixed or variable in size; in the later case of proportional thumbs, its length would indicate the size of the window in relation to the size of the whole document. While proportional thumbs were available in several GUIs including GEM, AmigaOS and PC/GEOS even in the early 1980s, Microsoft provided them not before the release of Windows 95. A proportional thumb that completely fills the trough indicates that the entire document is being viewed, at which point the scrollbar may temporarily become hidden. The proportional thumb can also sometimes be adjusted by dragging its ends. In this case it would adjust both the position and the zooming of the document, where the size of the thumb represents the degree of zooming applied.</article>
              
            
!

CSS

              
                body {
  background-color: #C851E8;
}

#example {
  position: absolute;
  top: 50%;
  left: 50%;
  transform: translate(-50%, -50%);
  width: 300px;
  height: 300px;
  border:1px #FFC2E9 solid;
  border-radius: 4px;
  padding: 10px;
}

*.-morulus-customsb {
  position:relative;
  width:100%;
  height:100%;
  overflow:hidden;
}

*.-morulus-customsb > figure:first-child {  
  margin: 0px !important;
  position: absolute;
  right: 4px !important;
  width: 4px !important;
  height: 100px;
  background-color: #FFC2E9;
}

*.-morulus-customsb > *:last-child {
  overflow-y: scroll;
  height: 100%;
  width: 100%;
  padding-right: 20px;
}
              
            
!

JS

              
                // Perform custom scrollbar
window.morulusCustomSb = (function() {
	var nu=navigator.userAgent,
  aus=['Mozilla','IE'],
  // Remove event listner polyfill
  removeEventListner = function(el, type, handler) {
		if ( el.addEventListener ) {
      el.removeEventListener(type, handler, false);
    }  else if ( elem.attachEvent ) {
      el.detachEvent("on" + type, handler);
    } else {
      el["on"+type] = null;
    };
  },
  // Event listner polyfill
 	eventListner = function(el, type, handler, once) {
    	var realhandler = once ? function() {
        removeEventListner(el, type, realhandler);
			} : handler;
      if ( el.addEventListener ) {
        listen = el.addEventListener( type, handler, false );
      } else if (el.attachEvent) {
         listen = el.addEventListener( 'on'+type, handler, false );
      } else {
        el['on'+type] = handler;
      }
      return el;
  },
  retfalse = function() { return !!0; },
  disableSelection = function(el) {
    	if (nu.indexOf(aus[0]) != -1) // FF
      el.style['MozUserSelect']='none';
    	else if (nu.indexOf(aus[1]) != -1) // IE
      eventListner(el, 'selectstart.disableTextSelect', retfalse);
    	else 
      eventListner(el, 'mousedown.disableTextSelect', retfalse);
	},
  enableSelection = function(el) {
   		if (nu.indexOf(aus[0]) != -1) // FF
      el.style['MozUserSelect']='';
    	else if (nu.indexOf(aus[1]) != -1) // IE
      removeEventListner(el, 'selectstart.disableTextSelect', retfalse);
    	else 
      removeEventListner(el, 'mousedown.disableTextSelect', retfalse);
  }
  return function(a) {

    var 
    listen,
    i,
    d=document,
    s, // Scrollable
    n, // Custom scrollbar wrapper
    r, // Runner
    height, // Runner height
    scrollTop, // Start scroll top,
    // Scroll handler    
    handlerScroll = function(e) {
			
      r.style.top = ( (100 - parseInt(r.style.height)) * (s.scrollTop/(s.scrollHeight-s.clientHeight)) )+'%';
    },
    drag = !!0,
    screenY = 0,
    handlerMove = function(e) {
    	var d = ((height*(scrollTop/(s.scrollHeight-s.clientHeight)))+(e.screenY-screenY));
      if (d>height) d = height;
      else if (d<0) d = 0;
      // set Scroll top
      s.scrollTop = Math.round((s.scrollHeight-s.clientHeight)*(d/height));
		},
    handlerUp = function(e) {
      drag=!!0;
      // Enable selection
      enableSelection(s);
      // remove listen for window move
   		removeEventListner(window, 'mousemove', handlerMove);
      e.stopPropagation();
		},
    handlerDown = function(e) {
      drag=!0;screenY=e.screenY; 
      height=s.clientHeight-parseInt(window.getComputedStyle(r).height);
      scrollTop=s.scrollTop;
      // Disable selection
      disableSelection(s);
      // Listen for window move
    	eventListner(window, 'mousemove', handlerMove);
      eventListner(window, 'mouseup', handlerUp, true);
      e.preventDefault();
      return false;
		},
    handlerWrapDown = function(e) {
     if(e.offsetX>n.offsetWidth-20){
        s.scrollTop = Math.round((s.scrollHeight-s.clientHeight)*(e.offsetY/n.offsetHeight));
        handlerDown(e);
      }
    },
    n=d.createElement('div');
    r=d.createElement('figure');
    s=d.createElement('div');
    
    // Wrap each insert elements
    for (i=0;i<a.childNodes.length;i++) {
      s.appendChild(a.childNodes[0]);
    }
    a.appendChild(n);
    n.appendChild(r);
    n.appendChild(s);
    n.className = '-morulus-customsb';
    // Set size of runner
    r.style.height = (100*(s.clientHeight/s.scrollHeight)
     .toFixed(2))+'%';
    // Listen for scroll
    eventListner(s,'scroll',handlerScroll);
    // Listen for drug
    eventListner(r,'mousedown',handlerDown);
    eventListner(r,'mouseup',handlerUp);
    // Listerb for drug on wrapper
    eventListner(n,'mousedown',handlerWrapDown);
  };
})();
// Execute
morulusCustomSb(document.getElementsByTagName('article')[0])
              
            
!
999px

Console