cssAudio - Activefile-genericCSS - ActiveGeneric - ActiveHTML - ActiveImage - ActiveJS - ActiveSVG - ActiveText - Activefile-genericVideo - ActiveLovehtmlicon-new-collectionicon-personicon-teamlog-outoctocatpop-outspinnerstartv

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.

            
              <div class="slider3d first">
  <div class="slider3d__wrapper">
    <div class="slider3d__inner">
      <div class="slider3d__rotater">
        <div class="slider3d__item">
          <h2 class="slider3d__heading" data-text="SO HEADING">SO HEADING</h2>
        </div>
        <div class="slider3d__item">
          <h2 class="slider3d__heading" data-text="MUCH ROTATION">MUCH ROTATION</h2>
        </div>
        <div class="slider3d__item">
          <h2 class="slider3d__heading" data-text="VERY 3D">VERY 3D</h2>
        </div>
        <div class="slider3d__item">
          <h2 class="slider3d__heading" data-text="SUCH JAVASCRIPT">SUCH JAVASCRIPT</h2>
        </div>
        <div class="slider3d__item">
          <h2 class="slider3d__heading" data-text="WOW WOW!">WOW WOW!</h2>
        </div>
      </div>
    </div>
  </div>
  <div class="slider3d__controls">
    <div class="slider3d__handle">
      <div class="slider3d__handle__inner">
        <div class="slider3d__handle__rotater">
          <div class="slider3d__handle__item active">Page 1</div>
          <div class="slider3d__handle__item">Page 2</div>
          <div class="slider3d__handle__item">Page 3</div>
          <div class="slider3d__handle__item">Page 4</div>
          <div class="slider3d__handle__item">Page 5</div>
        </div>
      </div>
    </div>
    <div class="slider3d__control m--up"></div>
    <div class="slider3d__control m--down"></div>
  </div>
</div>
            
          
!
            
              *, *:before, *:after {
  box-sizing: border-box;
  margin: 0;
  padding: 0;
}

html, body {
  font-size: 62.5%;

  @media (max-width: 991px) {
    font-size: 50%;
  }

  @media (max-width: 768px) {
    font-size: 40%;
  }
}

body {
  background: #777;
}

$openSans: 'Open Sans', Helvetica, Arial, sans-serif;

// usage example - text-shadow: text3d(#fff, 38, 0.3, 6%);
@function text3d($color, $depth: 20, $colorStep: 1, $colorOffset: 10%, $xStep: 0.02rem, $yStep: -0.03rem) {
  $startColor: darken($color, $colorOffset);
  $ts: ();
  @for $i from 1 through $depth {
    $c: darken($startColor, $colorStep * $i * 1%);
    $x: $xStep * $i;
    $y: $yStep * $i;
    $ts: append($ts, $x $y 0 $c, comma);
  }
  @return $ts;
}

%fullHeightEl {
  position: relative;
  height: 100%;
  transform-style: preserve-3d;
}

.slider3d {
  $sliderHeight: 100vh;

  overflow: hidden;
  position: relative;
  height: $sliderHeight;
  font-family: $openSans;

  &.no-select {
    user-select: none;
  }

  &__wrapper {
    z-index: 1;
    position: relative;
    height: 100%;
  }

  &__inner {
    @extend %fullHeightEl;
  }

  &__rotater {
    @extend %fullHeightEl;
  }

  &__item {
    position: absolute;
    left: 0;
    top: 0;
    width: 100%;
    height: 100%;
    background-size: cover;
    backface-visibility: hidden;
    background-color: #000;
    transform-style: preserve-3d;

    &:nth-child(1) {
      background-image: url('https://s3-us-west-2.amazonaws.com/s.cdpn.io/142996/3d-slider-1.jpg');
    }
    &:nth-child(2) {
      background-image: url('https://s3-us-west-2.amazonaws.com/s.cdpn.io/142996/3d-slider-2.jpg');
    }
    &:nth-child(3) {
      background-image: url('https://s3-us-west-2.amazonaws.com/s.cdpn.io/142996/3d-slider-3.jpg');
    }
    &:nth-child(4) {
      background-image: url('https://s3-us-west-2.amazonaws.com/s.cdpn.io/142996/3d-slider-4.jpg');
    }
    &:nth-child(5) {
      background-image: url('https://s3-us-west-2.amazonaws.com/s.cdpn.io/142996/3d-slider-5.jpg');
    }

  }

  &__heading {
    position: absolute;
    left: 0;
    top: 50%;
    width: 100%;
    margin-top: -6rem;
    text-align: center;
    font-size: 12rem;
    line-height: 1;
    text-transform: uppercase;
    color: #ffffff;
    transform: translateZ(3rem) scale(0.5);
    opacity: 0;
    text-shadow: text3d(#fff, 38, 0.3, 6%);
    transition: transform 0.4s, opacity 0.4s;
    transition-delay: 0.2s;
    transition-timing-function: cubic-bezier(.71,.59,.4,1.5);

    .slider3d.slider-ready & {
      transform: translateZ(3rem);
      opacity: 1;
    }
  }

  &__controls {
    display: none;

    .slider3d.with-controls & {
      display: block;
    }
  }

  &__handle {
    z-index: 2;
    position: absolute;
    right: 0;
    top: 50%;
    width: 15rem;
    height: 7rem;
    margin-top: -3.5rem;
    perspective-origin: 100% 50%;
    cursor: url('data:image/svg+xml;base64,PHN2ZyB4bWxucz0iaHR0cDovL3d3dy53My5vcmcvMjAwMC9zdmciIHdpZHRoPSIyNCIgaGVpZ2h0PSIyNCIgdmlld0JveD0iMCAwIDI0IDI0IiBlbmFibGUtYmFja2dyb3VuZD0ibmV3IDAgMCAyNCAyNCI+PHBhdGggZmlsbD0iI2ZmZiIgZD0iTTkuNCA0LjhsLTIuOS0yLjhoOC41djguNWwtMi44LTIuOHMtMS4yIDEuNC0xLjIgNC4zYzAgMy4xIDEuMiA0LjQgMS4yIDQuNGwyLjgtMi45djguNWgtOC41bDIuOC0yLjhzLTIuMy0yLjItMi4zLTcuMmMwLTQuOSAyLjQtNy4yIDIuNC03LjJ6Ii8+PHBhdGggZD0iTTEyLjIgNi4zcy0yLjIgMS44LTIuMiA1LjdjMCA0LjEgMi4xIDUuOCAyLjEgNS44bDEuOC0xLjh2NWgtNWwxLjgtMS44cy0yLjctMi4xLTIuNy03LjJjMC01IDIuOC03LjEgMi44LTcuMWwtMS45LTEuOWg1LjF2NS4xbC0xLjgtMS44Ii8+PC9zdmc+'), ns-resize;

    .m--xAxis & {
      left: 50%;
      right: auto;
      top: auto;
      bottom: 0;
      margin-left: -7.5rem;
      margin-top: 0;
      perspective-origin: 50% 100%;
    }

    &__inner {
      @extend %fullHeightEl;
    }

    &__rotater {
      @extend %fullHeightEl;
    }

    &__item {
      position: absolute;
      left: 0;
      top: 0;
      width: 100%;
      height: 100%;
      background: #000;
      text-align: center;
      font-size: 1.8rem;
      line-height: 7rem;
      text-transform: uppercase;
      font-weight: bold;
      color: #fff;
      user-select: none;

      &:after {
        content: "";
        z-index: -1;
        position: absolute;
        left: 0;
        top: 0;
        width: 100%;
        height: 100%;
        background: rgba(255,255,255,0.1);
        transition: opacity 0.3s;
      }

      &.active {

        &:after {
          opacity: 0;
        }
      }
    }
  }

  &__control {
    z-index: 3;
    position: absolute;
    right: 0;
    top: 50%;
    width: 15rem;
    height: 4rem;
    margin-top: -2rem;
    cursor: pointer;

    .m--xAxis & {
      left: 50%;
      right: auto;
      top: auto;
      bottom: 0;
      width: 6rem;
      height: 7rem;
      margin-top: 0;
      margin-left: -3rem;
    }

    &:after {
      content: "";
      position: absolute;
      left: 50%;
      top: 50%;
      width: 1rem;
      height: 1rem;
      margin-left: -0.5rem;
      margin-top: -0.5rem;
      border: 2px solid #fff;
      border-left: none;
      border-bottom: none;
    }

    &.m--up {
      transform: translateY(-6rem);

      &:after {
        transform: rotate(-45deg);
      }

      .m--xAxis & {
        transform: translateX(-11.5rem);

        &:after {
          transform: rotate(-135deg);
        }
      }
    }
    &.m--down {
      transform: translateY(6rem);

      &:after {
        transform: rotate(135deg);
      }

      .m--xAxis & {
        transform: translateX(11.5rem);

        &:after {
          transform: rotate(45deg);
        }
      }
    }
  }
}
            
          
!
            
              (function() {
  var rotatingSlider = function(selector, options) {

    function initSingleSlider($el, options) {
      var $slider, $rotaters,
          $handle, $handleItems,
          numOfItems,
          angle, currentAngle = 0,
          prefix = ".slider3d__", 
          handlePrefix = prefix + "handle__",
          rotating = false;

      var defaultOptions = {
        xRotation: false,
        speed: 1100,
        dragSpeedCoef: 0.7,
        handleSpeedCoef: 6,
        easing: "ease",
        persMult: 1.6,
        handlePersMult: 3,
        scrollRotation: true,
        keysRotation: true,
        globalDragRotation: false,
        withControls: true,
        handleAndGlobalDrag: false,
        allowDragDuringAnim: false,
        allowScrollDuringAnim: false,
        allowKeysDuringAnim: false,
        allowControlsDuringAnim: false
      };

      var __opts = $.extend(defaultOptions, options);
      
      var axis = (__opts.xRotation) ? "Y" : "X";
      var angleMult = (__opts.xRotation) ? 1 : -1;

      function handleActiveItem() {
        if (!__opts.withControls) return;
        $handleItems.removeClass("active");
        var a = currentAngle % 360 / angle;
        if (a < 0) a = numOfItems + a;
        if (a > 0) a = a + 1;
        if (!a) a = 1;
        $handleItems.eq(a - 1).addClass("active");
      };

      function rotateSlider(delta) {
        var newAngle = currentAngle + delta * angle;

        $rotaters.css({"transform": "rotate"+axis+"("+ (newAngle * angleMult * -1) +"deg)",
                       "transition": "transform " + __opts.speed / 1000 + "s " + __opts.easing});
        currentAngle = newAngle;

        setTimeout(function() {
          $rotaters.css("transition", "transform 0s");
          handleActiveItem();
          rotating = false;
        }, __opts.speed);
      };
      
      function navigateUp() {
        rotateSlider(-1);
      };
      
      function navigateDown() {
        rotateSlider(1);
      };

      function scrollHandler(e) {
        if (rotating && !__opts.allowScrolluringAnim) return;
        rotating = true;
        var delta = e.originalEvent.wheelDelta || -e.originalEvent.detail;
        if (delta > 0) {
          navigateUp();
        } else if (delta < 0) {
          navigateDown();
        }
      };
      
      function keydownHandler(e) {
        if (rotating && !__opts.allowKeysDuringAnim) return;
        rotating = true;
        if (e.which === 38) {
          navigateUp();
        } else if (e.which === 40) {
          navigateDown();
        }
      }

      function dragRotationHandler(e) {
        if (rotating && !__opts.allowDragDuringAnim) return;
        rotating = true;
        $slider.addClass("no-select");
        
        var startVal;
        if (__opts.xRotation) {
          startVal = e.pageX || e.originalEvent.touches[0].pageX;
        } else {
          startVal = e.pageY || e.originalEvent.touches[0].pageY;
        }
        var sliderS = (__opts.xRotation) ? $slider.width() : $slider.height();
        var deltaVal = 0;
        var newAngle;
        var angleDelta;
        var isHandle = $(this).hasClass("js-handle");
        var rotationCoef;
        if (isHandle) {
          rotationCoef = __opts.handleSpeedCoef;
        } else {
          rotationCoef = __opts.dragSpeedCoef;
        }
        
        if (__opts.scrollRotation) {
          $slider.off("mousewheel DOMMouseScroll", scrollHandler);
        }

        $(document).on("mousemove touchmove", function(e) {
          var val;
          if (__opts.xRotation) {
            val = e.pageX || e.originalEvent.touches[0].pageX;
          } else {
            val = e.pageY || e.originalEvent.touches[0].pageY;
          }
          deltaVal = (startVal - val) / sliderS * rotationCoef;
          newAngle = currentAngle + deltaVal * angle;
          angleDelta = newAngle - currentAngle;

          $rotaters.css("transform", "rotate"+axis+"("+ (newAngle * angleMult * -1) +"deg)");
        });

        $(document).on("mouseup touchend", function(e) {
          $(document).off("mousemove touchmove mouseup touchend");
          $slider.removeClass("no-select");

          if (!deltaVal) {
            rotating = false;
            if (__opts.scrollRotation) {
              $slider.on("mousewheel DOMMouseScroll", scrollHandler);
            }
            return;
          }
          
          var slidesRotated = Math.round(angleDelta / angle);
          rotateSlider(slidesRotated);
          deltaVal = 0;

          setTimeout(function() {
            if (__opts.scrollRotation) {
              $slider.on("mousewheel DOMMouseScroll", scrollHandler);
            }
          }, __opts.speed);
        });

      };

      function initControls() {
        var $controls = $(prefix + "controls");
        $handle = $(prefix + "handle", $slider);
        var $handleInner = $(handlePrefix + "inner", $handle);
        $handleItems = $(handlePrefix + "item", $handle);
        var s = (__opts.xRotation) ? $handle.width() : $handle.height();
        var pers = s * __opts.handlePersMult;
        var depth = s / 2 / Math.tan(angle / 2 * Math.PI/180);
        
        $slider.addClass("with-controls");
        $handle.css({"-webkit-perspective": pers + "px",
                     "perspective": pers + "px"})
          .addClass("js-handle");
        $handleInner.css("transform", "translateZ(-"+ depth +"px)");
        
        if (__opts.xRotation) $controls.addClass("m--xAxis");

        $handleItems.each(function(index) {
          $(this).css("transform", "rotate"+axis+"("+ (index * angle * angleMult) +"deg) translateZ("+ depth +"px)");
        });

        $rotaters = $(prefix + "rotater, "+ handlePrefix + "rotater", $slider);
        
        $handle.on("mousedown touchstart", dragRotationHandler);
        
        $(document).on("click", ".slider3d__control", function() {
          if (rotating && !__opts.allowControlsDuringAnim) return;
          rotating = true;
          if ($(this).hasClass("m--up")) {
            navigateUp();
          } else {
            navigateDown();
          }
        });
      };

      function initSlider($el) {
        $slider = $el;
        var $wrapper = $(prefix + "wrapper", $slider);
        var $inner = $(prefix + "inner", $slider);
        var $items = $(prefix + "item", $slider);
        numOfItems = $items.length;
        angle = 360 / numOfItems;
        var s = (__opts.xRotation) ? $slider.width() : $slider.height();
        var pers = s * __opts.persMult;
        var depth = s / 2 / Math.tan(angle / 2 * Math.PI/180);

        $wrapper.css({"-webkit-perspective": pers + "px",
                      "perspective": pers + "px"});
        $inner.css("transform", "translateZ(-"+ depth +"px)");

        $items.each(function(index) {
          $(this).css("transform", "rotate"+axis+"("+ (index * angle * angleMult) +"deg) translateZ("+ depth +"px)");
        });

        $slider.addClass("slider-ready");

        $rotaters = $(prefix + "rotater", $slider);
        
        if (__opts.scrollRotation) {
          $slider.on("mousewheel DOMMouseScroll", scrollHandler);
        }
        if (__opts.keysRotation) {
          if (!$slider.attr("tabindex")) {
            $slider.attr("tabindex", 1);
          }
          $slider.on("keydown", keydownHandler);
        }
        if (__opts.globalDragRotation) {
          $slider.on("mousedown touchstart", dragRotationHandler);
        }
        if (__opts.withControls) {
          initControls();
        }
      };
      
      initSlider($el);
      
    }

    function globalInit() {
      $(selector).each(function() {
        initSingleSlider($(this), options);
      });
    };

    function debounce(func, wait, immediate) {
      var timeout;
      return function() {
        var context = this, args = arguments;
        var later = function() {
          timeout = null;
          if (!immediate) func.apply(context, args);
        };
        var callNow = immediate && !timeout;
        clearTimeout(timeout);
        timeout = setTimeout(later, wait);
        if (callNow) func.apply(context, args);
      };
    };

    var resizeFn = debounce(function() {
      globalInit();
    }, 100);

    $(window).on("resize", resizeFn);

    globalInit();

  };

  window.rotatingSlider = rotatingSlider;
}());

$(document).ready(function() {

  rotatingSlider(".slider3d", {xRotation: false, globalDragRotation: true});

});
            
          
!
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