css Audio - Active file-generic CSS - Active Generic - Active HTML - Active JS - Active SVG - Active Text - Active file-generic Video - Active header Love html icon-new-collection icon-person icon-team numbered-list123 pop-out spinner split-screen star tv

Pen Settings

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

You're using npm packages, so we've auto-selected Babel for you here, which we require to process imports and make it all work. If you need to use a different JavaScript preprocessor, remove the packages in the npm tab.

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

Use npm Packages

We can make npm packages available for you to use in your JavaScript. We use webpack to prepare them and make them available to import. We'll also process your JavaScript with Babel.

⚠️ This feature can only be used by logged in users.

Code Indentation


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.

HTML Settings

Here you can Sed posuere consectetur est at lobortis. Donec ullamcorper nulla non metus auctor fringilla. Maecenas sed diam eget risus varius blandit sit amet non magna. Donec id elit non mi porta gravida at eget metus. Praesent commodo cursus magna, vel scelerisque nisl consectetur et.

              <div id="container" class="slider-container">
    <span class="slider-handle"></span>
              html, body {
	height: 100%;
  margin: 0;
  padding: 0;

* {
  outline: 0;

#container {
	position: relative;
	height: 100%;

.slider-handle {

	position: absolute;

	height: 44px;
	width: 44px;

	/* center the element */
	left: 50%;
	top: 50%;

	margin-left: -22px;
	margin-top: -22px;

	border-radius: 50%;

	background: #dc717d url('data:image/svg+xml;utf8,<svg xmlns="http://www.w3.org/2000/svg" width="32" height="32" viewBox="0 0 32 32"><path fill="#FFF" d="M13 21l-5-5 5-5m6 0l5 5-5 5"/></svg>') no-repeat center center;
	cursor: move;

	box-shadow: 0 0 0 6px rgba(0, 0, 0, 0.2), 0 0 10px rgba(0, 0, 0, 0.6), inset 0 1px 0 rgba(255, 255, 255, 0.3);
	z-index: 2;


.slider-handle.draggable {
	background-color: #445b7c;
              // Proof of concept by Illya Moskvin, IMA Lab, Indianapolis Museum of Art
// MIT License, free (gratis and libre) for any use, we take no responsibility :P

// Image comparison slider, loosely based on the following:
// https://codyhouse.co/gem/css-jquery-image-comparison-slider/

// Initialize the viewer
var viewer = OpenSeadragon({
    id:              "container",
    xmlns:           "http://schemas.microsoft.com/deepzoom/2008",
    prefixUrl:       "//openseadragon.github.io/openseadragon/images/"

// Create a point exactly in the middle of the viewport
var $viewer = $('#container');

var middle = new OpenSeadragon.Point( $viewer.width() / 2, $viewer.height() / 2 );

function updateMiddle( offset ) {
    middle.x = offset;

// Keep track of the two images we're splitting
var leftImage = null;
var rightImage = null;

var leftRect = new OpenSeadragon.Rect( 0,0,0,0 );
var rightRect = new OpenSeadragon.Rect( 0,0,0,0 );

viewer.addTiledImage( {
    tileSource: 'https://dlcs.io/iiif-img/3/2/04fbbb28-d5a7-4408-b7da-800c4e65eda3/info.json',
    success: function( event ) {

        leftImage = event.item;


viewer.addTiledImage( {
    tileSource: 'https://dlcs.io/iiif-img/3/2/8034eb5b-9c90-4471-ad68-52124232ec0c/info.json',
    success: function( event ) {

        rightImage = event.item;


// Handle pan and zoom events
viewer.addHandler('animation', function (viewer) {



// Basic function to check when both images are loaded
function imagesLoaded() {
    if( leftImage && rightImage ) {

        leftRect.height = leftImage.getContentSize().y;
        rightRect.height = rightImage.getContentSize().y;




function imagesClip(  ) {

    var rox = rightImage.viewerElementToImageCoordinates( middle ).x;
    var lox = leftImage.viewerElementToImageCoordinates( middle ).x;

    rightRect.x = rox ;
    rightRect.width = rightImage.getContentSize().x - rox;

    leftRect.width = lox;

    leftImage.setClip( leftRect );
    rightImage.setClip( rightRect );


function initClip() {

    //console.log( leftImage, rightImage );
    //console.log( rightImage.getContentSize() );

    // TODO: Abstract this away
    var $handle = $('.slider-handle');
    var $container = $handle.parents('.slider-container');

    // We will assume that the width of the handle element does not change
    var dragWidth = $handle.outerWidth();

    // However, we will track when the container resizes
    var containerWidth, containerOffest, minLeft, maxLeft;

    function updateContainerDimensions() {

        containerWidth = $container.outerWidth();
        containerOffset = $container.offset().left;
        minLeft = containerOffset + 10;
        maxLeft = containerOffset + containerWidth - dragWidth - 10;

        // Spoof the mouse events
        var offset = $handle.offset().left + dragWidth / 2;
        var event;

        // Bind the drag event
        event = new jQuery.Event("mousedown");
        event.pageX = offset;

        $handle.trigger( event );

        // Execute the drag event
        event = new jQuery.Event("mousemove");
        event.pageX = offset;

        $container.trigger( event );

        // Unbind the drag event


    // Retrieve initial container dimention 

    // Bind the container resize
    $(window).resize( updateContainerDimensions );

    // We are just going to assume jQuery is loaded by now
    // Eventually, I'll make this work without jQuery
    $handle.on("mousedown vmousedown", function(e) {

        var xPosition = $handle.offset().left + dragWidth - e.pageX;

        function trackDrag(e) {

            var leftValue = e.pageX + xPosition - dragWidth;
            //constrain the draggable element to move inside its container
            leftValue = Math.max(leftValue, minLeft);
            leftValue = Math.min(leftValue, maxLeft);

            var widthPixel = (leftValue + dragWidth/2 - containerOffset);
            var widthFraction = widthPixel/containerWidth;
            var widthPercent = widthFraction*100+'%';
            $handle.css('left', widthPercent);

            updateMiddle( widthPixel );
            imagesClip( );


        $container.on("mousemove vmousemove", trackDrag);

        $handle.add($container).one("mouseup vmouseup", function(e) {
            $container.unbind("mousemove vmousemove", trackDrag);



🕑 One or more of the npm packages you are using needs to be built. You're the first person to ever need it! We're building it right now and your preview will start updating again when it's ready.
Loading ..................