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.

            
              .carousel.right
  .indicator
  .wrap
    ul
      li
        img(src='http://ppcdn.500px.org/23718959/f216a69d1cb7667436a1e6a33c7e4b2894d0fe18/4.jpg')
      li
        img(src='http://ppcdn.500px.org/72233281/5e145f8f95427805045dbaf1ec2cf17bcb4b25b3/3.jpg')
      li
        img(src='http://ppcdn.500px.org/72190239/1ac03d25646f92afd4d80ed8e6f2c1cfc78635b5/4.jpg')
      li
        img(src='http://ppcdn.500px.org/58739696/b0c33312552e8581ef457720bb924f16421dcec8/3.jpg')
      li
        img(src='http://ppcdn.500px.org/43028892/84b059f25810f07962ae46e63c44c625b2f9b9e6/2048.jpg')
      li
        img(src='http://ppcdn.500px.org/33154839/a53aeaca99ee94a9803f445fd30163142f308829/3.jpg')
      li
        img(src='http://ppcdn.500px.org/17981845/d1fdacaf5818108c248b05cd472329d314e732d3/3.jpg')
            
          
!
            
              $carouselHeight : 200px;
$padding        : 8px;
$indicatorColor : #D82B6A;
$bodyBG         : #292B2C;
$bgColor        : lighten($bodyBG, 16);

body{ background:$bodyBG; }

.carousel{ 
  display:block; 
  position: absolute;
  -webkit-transform: translateZ(0); 
  /*  for demo only */
  top:0; right:0; bottom:0; left:0;
  width:55%; 
  height:$carouselHeight;
  min-width:550px;
  margin:auto;
  font-size:0;
  background:$bgColor;
  padding:$padding;
  border-radius:6px;
  box-shadow:0 4px 10px #000;
  /********************/
  
  height:$carouselHeight; 
  -webkit-overflow-scrolling:touch;
  
    .touch &{ overflow:auto; } /* for tablets */
  
    &:before, &:after{ 
      content:'';
      opacity:0; 
      position:absolute; 
      top:0;
      bottom:0;
      z-index:2;
      width:50px;
      font-size:80px;
      line-height:$carouselHeight - 10;
      font-family:arial;
      color:#555;
      font-weight:bold;
      pointer-events:none;
      transition:0.2s ease-out; 
    }
    &:before{ 
      content:'\2039'; 
      left:0; text-align:left;
      text-indent:-20px;
      box-shadow:50px 0 20px -20px $bodyBG inset; 
    }
    &:after{ 
      content:'\203A'; 
      right:0; text-align:right;
      text-indent:40px;
      box-shadow:-50px 0 20px -20px $bodyBG inset; 
    }
  
    &.right:after, &.left:before{ 
      opacity:1;
    }
  
    &.right{
        &:after{ right:0; text-indent:60px; }
    }
    &.left{
        &:before{ left:0; text-indent:-40px; }
    }
  
    > a{ 
      position:absolute; 
      margin:0; top:0; bottom:0; 
      color:#CCC; 
      font-size:1.5em; 
      transition:0.1s;
        &:hover{ color:#FFF; }
        &.prev{ left:-20px; }
        &.next{ right:-20px; }
    }
    > .indicator{  
      pointer-events:none;
      position:absolute; 
      z-index:4;
      bottom:0; left:0;
      background:$indicatorColor;
      height:4px;
      border-radius:10px;
      opacity:0;
      transition:opacity 0.2s, bottom 0.2s;
    }
  
    &:hover{  
      > .indicator{ opacity:1; bottom:-10px; }
    }
  
    > .wrap{ overflow:hidden; border-radius:5px;
      > ul{ 
        list-style:none; 
        white-space:nowrap; 
        height:$carouselHeight;
          > li{ 
            display:inline-block; 
            vertical-align:middle; 
            height:100%; 
            margin:0 0 0 5px; 
            position:relative; 
            overflow:hidden; 
            transition:0.25s ease-out;
            &:first-child{ margin:0; }
            > img{ 
               display:block; 
               height:100%; 
               margin:auto; 
               vertical-align:bottom; 
               position:relative; 
               z-index:1; 
               transition:1s ease; 
            }
            //&:hover img{ transform:scale(1.1); }
          }
       }
    }
}

            
          
!
            
              // Hover-Carousel jQuery plugin
// By Yair Even-Or
// https://github.com/yairEO/hover-carousel
// http://dropthebit.com

;(function($){
    "use strict";

    var bindToClass      = 'carousel',
        containerWidth   = 0,
        scrollWidth      = 0,
        posFromLeft      = 0,    // Stripe position from the left of the screen
        stripePos        = 0,    // When relative mouse position inside the thumbs stripe
        animated         = null,
        $indicator, $carousel, el, $el, ratio, scrollPos, nextMore, prevMore, pos, padding;

    // calculate the thumbs container width
    function calc(e){
        $el = $(this).find(' > .wrap');
        el  = $el[0];
        $carousel = $el.parent();
        $indicator = $el.prev('.indicator');

        nextMore = prevMore  = false; // reset

        containerWidth       = el.clientWidth;
        scrollWidth          = el.scrollWidth; // the "<ul>"" width
        padding              = 0.2 * containerWidth; // padding in percentage of the area which the mouse movement affects
        posFromLeft          = $el.offset().left;
        stripePos            = e.pageX - padding - posFromLeft;
        pos                  = stripePos / (containerWidth - padding*2);
        scrollPos            = (scrollWidth - containerWidth ) * pos;
        
        if( scrollPos < 0 )
          scrollPos = 0;
        if( scrollPos > (scrollWidth - containerWidth) )
          scrollPos = scrollWidth - containerWidth;
      
        $el.animate({scrollLeft:scrollPos}, 200, 'swing');
        
        if( $indicator.length )
            $indicator.css({
                width: (containerWidth / scrollWidth) * 100 + '%',
                left: (scrollPos / scrollWidth ) * 100 + '%'
            });

        clearTimeout(animated);
        animated = setTimeout(function(){
            animated = null;
        }, 200);

        return this;
    }

    // move the stripe left or right according to mouse position
    function move(e){
        // don't move anything until inital movement on 'mouseenter' has finished
        if( animated ) return;

        ratio     = scrollWidth / containerWidth;
        stripePos = e.pageX - padding - posFromLeft; // the mouse X position, "normalized" to the carousel position

        if( stripePos < 0)
            stripePos = 0;

        pos = stripePos / (containerWidth - padding*2); // calculated position between 0 to 1
        // calculate the percentage of the mouse position within the carousel
        scrollPos = (scrollWidth - containerWidth ) * pos;   

        el.scrollLeft = scrollPos;
        if( $indicator[0] && scrollPos < (scrollWidth - containerWidth) )
          $indicator[0].style.left = (scrollPos / scrollWidth ) * 100 + '%';

        // check if element has reached an edge
        prevMore = el.scrollLeft > 0;
        nextMore = el.scrollLeft < (scrollWidth - containerWidth);

        $carousel.toggleClass('left', prevMore);
        $carousel.toggleClass('right', nextMore);
    }

    $.fn.carousel = function(options){
        $(document)
            .on('mouseenter.carousel', '.' + bindToClass, calc)
            .on('mousemove.carousel', '.' + bindToClass, move);
    };

    // automatic binding to all elements which have the class that is assigned to "bindToClass"
    $.fn.carousel();

})(jQuery);

            
          
!
999px
🕑 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 ..................

Console