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.

Details

Privacy

Go PRO Window blinds lowered to protect code. Code Editor with window blinds (raised) and a light blub turned on.

Keep it secret; keep it safe.

Private Pens are hidden everywhere on CodePen, except to you. You can still share them and other people can see them, they just can't find them through searching or browsing.

Upgrade to PRO

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.

Template

Make Template?

Templates are Pens that can be used to start other Pens quickly from the create menu. The new Pen will copy all the code and settings from the template and make a new Pen (that is not a fork). You can view all of your templates, or learn more in the documentation.

Template URL

Any Pen can act as a template (even if you don't flip the toggle above) with a special URL you can use yourself or share with others. Here's this Pen's template URL:

Screenshot

Screenshot or Custom Thumbnail

Screenshots of Pens are shown in mobile browsers, RSS feeds, to users who chose images instead of iframes, and in social media sharing.

This Pen is using the default Screenshot, generated by CodePen. Upgrade to PRO to upload your own thumbnail that will be displayed on previews of this pen throughout the site and when sharing to social media.

Upgrade to PRO

HTML

              
                <div id="instruction"><p>When clicking on right half of the picture you get to the next image, when clicking on the left, the previous picture is shown. When clicking on the first picture, it doesn't matter where, always the next picture is shown - same for the last image - always the previous is shown when clicked.</p><p>switching between the images is also possible by dragging and this is where the problem occurs in Safari. When clicking an image and moving the mouse slightly the first picture gets in the visible area.</p></div>

<div class="slidecounter"><span class="current">1</span> / <span class="total">6</span></div>

<ul class="slides show1">
    <li>
      <img src="http://lorempixel.com/400/200/sports" />
    </li><li>
      <img src="http://lorempixel.com/400/200/city" />
    </li><li>
      <img src="http://lorempixel.com/400/200/food" />
    </li><li>
      <img src="http://lorempixel.com/400/200/animals" />
    </li><li>
      <img src="http://lorempixel.com/400/200/nightlife" />
    </li><li>
      <img src="http://lorempixel.com/400/200/business" /></li>
</ul>
              
            
!

CSS

              
                .slides{
    height: 80vh;
    width: calc( 80vh * 1.5 );
    max-width: 100%;
    padding: 0;
    overflow: hidden;
    margin: 0 auto;
    list-style: none;
    white-space: nowrap;
    position: relative;
}

li{
    width: 100%;
    height: 100%;
    display: inline-block;
    position: relative;
    vertical-align: top;
    top: 0!important;
    transition: left 0.4s;
}

    
img{
    width: 100%;
    display: block;
}

.show1 li{ left: 0; }
.show2 li{ left: -100%; }
.show3 li{ left: -200%; }
.show4 li{ left: -300%; }
.show5 li{ left: -400%; }
.show6 li{ left: -500%; }

.slidecounter{ text-align: center; font-weight: bold; }
              
            
!

JS

              
                var start,stop;
$('.slides li').draggable({
    axis: "x",
    cursor: "move",
    snap: true,
    start: function(event, ui){
        start = ui.position.left;
    },
    drag: function(event, ui){
        if( ui.position.left < 0 ){
            $('li').css( 'left', ui.position.left );
        }
        else{
            // stop, wrong direction
            $('li').css( 'left', 0 );
        }
    },
    stop: function(event, ui){
        var distance = Math.abs( ui.position.left );
        stop = ui.position.left;
        direction = (start < stop) ? 'right' : 'left';

        if( distance > 50 ){
            if( direction == "left" ){ next(); }
            else{ prev(); }
        }
        else{
            stay();
        }
    }
});

function next(){
    var current = parseInt( $('.current').text() );
    var total = parseInt( $('.total').text() );

    if( current < $('li').length ){
        $('li').css('left', '');
        $('.slides').addClass( 'show'+(current+1) );
        $('.slides').removeClass( 'show'+(current) );

        $('.current').text( current + 1 );
    }
}

function prev(){
    var current = parseInt( $('.current').text() );

    //if not the first $('.slides')
    if( current > 1 ){
        $( 'li').css('left', '');
        $('.slides').addClass( 'show'+(current-1) );
        $('.slides').removeClass( 'show'+(current) );

        $('.current').text( current - 1 );
    }
}

function stay(){
    
}

// click or drag
var isDragging = false;
$( 'li').mousedown(function() {
    $(window).mousemove(function() {
        isDragging = true;
        $(window).unbind("mousemove");
    });
})
.mouseup(function( event ) {
    var wasDragging = isDragging;
    isDragging = false;
    $(window).unbind("mousemove");
    if (!wasDragging) {
        var width = $(this).width();
        var links = $(this).offset().left + width / 2;

        // click on the first image -> always next
        if( $(this).prev().length == 0 ){
            next();
        }
        // click on the last image --> always prev
        else if( $(this).next().length == 0 ){
            prev();
        }
        // left half clicked, previous image
        else if( event.pageX <= links ) {
            prev();
        }
        // right half clicked, next image
        else{
            next();
        }
    }
});
              
            
!
999px
Why did the programmer quit her job? She didn't get arrays.

Console