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.

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.

HTML

              
                <div id="c-jalousie" class="c-jalousie"
     data-slices="15"
     data-staggerSpeed="5"
     data-offset=".2"
     data-dist="50"
     data-transition-effect="jalousie"
     data-img-src = "http://www.wallpaperstop.com/wallpapers/space-wallpapers/cool-space-wallpaper-1680x1050-1009158.jpg">
</div>
              
            
!

CSS

              
                img {
    width: auto;
    max-width: 100%;
    height: auto;
}

.c-jalousie {
    width: 80vw;
    height: 80vh;
    position: absolute;
    top: 10vh;
    left: 10vw;
    box-sizing: border-box;
    transform-style: preserve-3d;
    transform-origin: center center;
    perspective: 1200px;
}

.c-jalousie__slice {
    box-sizing: border-box;
    display: block;
    position: absolute;
    top: 0;
    height: 100%;
    min-height: 100%;
    overflow: hidden;
    background-color: transparent;
    background-repeat: no-repeat;
    background-size: cover;
    text-align: center;
    backface-visibility: hidden;
}

.u-slice-number {
    display: inline-block;
    position: relative;
    margin-top: calc(40vh - 25px);
    margin-left: auto;
    margin-right: auto;
    height: 50px;
    width: 50px;
    color: yellow;
    font-weight: bold;
    font-size: 24px;
    line-height: 50px;
    border: 2px solid yellow;
    text-align: center;
    border-radius: 100%;
    background-color: rgba(255,255,0,.2);
    box-shadow: 0 0 1px 7px rgba(255,255,0,.1);
}
              
            
!

JS

              
                // Settings object
var SETTINGS = {
  slices: 0, // how many slices
  staggerSpeed: 0, // how long should slice animate anmitaion
  offset: 0, // offset between slices to start animating
  dist: 0, // how far to move slices (+ down, - up)
  transitionEffect: "", // which effect should be used
  image: {
    url: "", // the image url
    width: 0,
    height: 0
  },
  document: {
    width: 0, // needed to calculate px -> vw
    height: 0 // needed to calculate px -> vh
  },
  container: {
    width: 0,
    height: 0
  }
};

function buildSettings(obj) {
  SETTINGS.thisObj = obj;
  SETTINGS.slices = parseInt(obj.getAttribute('data-slices'));
  SETTINGS.staggerSpeed = parseFloat(obj.getAttribute('data-staggerSpeed'));
  SETTINGS.offset = parseFloat(obj.getAttribute('data-offset'));
  SETTINGS.dist = parseInt(obj.getAttribute('data-dist'));
  SETTINGS.transitionEffect = obj.getAttribute('data-transition-effect');
  SETTINGS.image.url = obj.getAttribute('data-img-src');
  SETTINGS.document.width = document.documentElement.clientWidth;
  SETTINGS.document.height = document.documentElement.clientHeight;
  SETTINGS.container.width = obj.clientWidth; // * 100;
  SETTINGS.container.height = obj.clientHeight; // * 100;
  // w & h to be set as soon as image is loaded; see later
  SETTINGS.image.width = 0;
  SETTINGS.image.height = 0;
}

function jalousieEffect(objs) {
  console.log(objs);
  var jalousieTL = new TimelineMax();  
  jalousieTL.set(['.c-jalousie__slice'], { 
    opacity: .1,
    transform: "rotateY(60deg)" 
  });
  
  console.log(jalousieTL.vars);
  console.log(jalousieTL.totalTime());

  /*
  jalousieTL.staggerFrom(objs, 1, {
    force3D: true,
    opacity: 0,
    scale: 0.2,
    rotationY: -33,
    rotationX: 90,
    ease:Elastic.easeOut
  }, 0.2 );
  */

  jalousieTL.staggerTo(objs, SETTINGS.staggerSpeed, {
    force3D: true,
    y: SETTINGS.dist,
    x: SETTINGS.dist,
    rotationX: 0,
    rotationY: 0,
    opacity: 1,
    ease: Elastic.easeOut
    //autoAlpha: 1
  }, SETTINGS.offset, 0.01, moveBack, [jalousieTL, objs]);

}

function moveBack(tl, params) {
  tl.staggerTo(params, SETTINGS.staggerSpeed, {
    force3D: true,
    y: 0,
    x: 0,
    rotationX: 0,
    rotationY: 0,
    opacity: 0,
    ease: Elastic.easeInOut
    //autoAlpha: 0
  }, SETTINGS.offset);
}
// Convert to vw: 1px = (100 / 500) = 0.2vw
// var newWidth = yourElement.outerwidth / document.documentElement.clientWidth * 100;
// yourElement.style.width = newWidth +'vw';

function buildJalousieEffect(obj) {

  // Define here, whether to use the whole document width or the dimensions of a container
  var containerWidth = SETTINGS.container.width;
  var containerHeight = SETTINGS.container.height;

  // Since we want to enlarge the image, DO NOT use SETTINGS.image.width,
  // but instead containerWidth
  var sliceWidth = (containerWidth / SETTINGS.slices);

  // Generate vw value
  var sliceWidthVW = ((containerWidth / SETTINGS.slices) / SETTINGS.document.width) * 100;
  // var sliceHeight = SETTINGS.image.height; // not needed here

  // set inline styles on slice element
  var bi = 'background-image:url("' + SETTINGS.image.url + '");';
  // add a little extra to overlap any potential gaps between the slices
  var w = 'width:' + (sliceWidthVW + 0.1) + 'vw;';

  for (var i = 0; i < SETTINGS.slices; i++) {

    var leftDist = i * sliceWidth;
    var leftDistVW = (leftDist / SETTINGS.document.width) * 100;

    var l = 'left:' + leftDistVW + 'vw;';
    var bp = 'background-position:-' + leftDistVW + 'vw 50%;';
    var bs = 'background-size:' + containerWidth + 'px auto;';

    var styles = w + l + bi + bs + bp;

    // Create slice element, add styles and append it to the 
    // document AND save it to a var for further use
    var el = document.createElement('span');
    el.setAttribute('style', styles);
    el.classList.add('c-jalousie__slice');
    var oneSlice = obj.appendChild(el);

    // create element for counter number and appendit to the slice
    var counter = document.createElement('div');
    counter.innerHTML = i + 1;
    counter.classList.add('u-slice-number');
    oneSlice.appendChild(counter);

  }

  // "querySelector" finds ONLY the first matching element.
  // To get all elements with the same class, use "querySelectorAll"
  var objs = obj.querySelectorAll('.c-jalousie__slice');
  jalousieEffect(objs);
}

// IEFE to create Local context
(function() {
  "use strict";

  // Get the div container, upon which the effect is supposed to take effect
  var obj = document.querySelector('.c-jalousie');
  buildSettings(obj);

  // Image() Object upon which the preloading of an image source is performed
  var downloadingImage = new Image();

  downloadingImage.onload = function() {
    if (downloadingImage.complete && downloadingImage.naturalWidth !== 0) {
      buildJalousieEffect(obj);
    } else {
      console.log("Something went wrong laoding the image");
    }
  };

  downloadingImage.onerror = function() {
    console.log("Error loading image")
  };

  downloadingImage.src = SETTINGS.image.url;

  downloadingImage.addEventListener('load', function() {
    //set missing images SETTINGS (width, height; 
    //can be done only, once the image is loaded)
    SETTINGS.image.width = this.naturalWidth;
    SETTINGS.image.height = this.naturalHeight;
  });

})();
              
            
!
999px

Console