cssAudio - ActiveCSS - ActiveGeneric - ActiveHTML - ActiveImage - ActiveJS - ActiveSVG - ActiveText - Activefile-genericVideo - Activehtmlicon-personicon-teamoctocatspinnerstartv

Pen Settings

CSS Base

Vendor Prefixing

Add External CSS

These stylesheets will be added in this order and before the code you write in the CSS editor. You can also add another Pen here, and it will pull the CSS from it. Try typing "font" or "ribbon" below.

Quick-add: + add another resource

Add External JavaScript

These scripts will run in this order and before the code in the JavaScript editor. You can also link to another Pen here, and it will run the JavaScript from it. Also try typing the name of any popular library.

Quick-add: + add another resource

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.

            
              .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
Close

Asset uploading is a PRO feature.

As a PRO member, you can drag-and-drop upload files here to use as resources. Images, Libraries, JSON data... anything you want. You can even edit them anytime, like any other code on CodePen.

Go PRO

Loading ..................

Console