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.

            
              <h1>Some basic demos</h1>
<h3>Rotation</h3>
<img src="http://placekitten.com/700/400?1" id="sample1"/>​

<h3>Move up or down</h3>
<img src="http://placekitten.com/700/400?1" id="sample2"/>​

<h3>Move out</h3>
<img src="http://placekitten.com/700/400?3" id="sample3"/>​

<h3>Zoom vertical</h3>
<img src="http://placekitten.com/700/400?3" id="sample4"/>​


<h3>Vertical flip</h3>
<img src="http://placekitten.com/700/400?3" id="sample5"/>​


<p>Created by <a href="https://twitter.com/FWeinb">Fabrice Weinberg</a> 2012</p>
            
          
!
            
              body{
  font-family:Helvetica, sans-serif;
  /*https://subtlepatterns.com/shattered/ by Luuk van Baars.*/
  background-image:url(https://dl.dropbox.com/u/5319/codepen/shatterd.png);
  margin:50px auto;
  width:700px;
}

.sample1 span, .sample2 span, .sample3 span, .sample4 span{
  transition:all 1s;
}
.sample1:hover span{
  transform:rotate(360deg);
}

.sample2 span:hover:nth-child(even){
  transform:translateY(30px);
}

.sample2 span:hover:nth-child(odd){
  transform:translateY(-30px);
}

.sample3{
  overflow:hidden;
}
.sample3:hover span:first-child{
	transform:translateX(-500px);
}

.sample3:hover span:last-child{
	transform:translateX(500px);
}
.sample4 span:hover{
	transform: scale(1.2);
}

.sample5 span{
	perspective:100px;
  transform:rotateX(10deg);
}
.sample5:hover span{
	animation:flip 1s alternate;
}

.sample5:hover span:nth-child(2){
	animation-delay:.2s;
}
.sample5:hover span:nth-child(3){
	animation-delay:.4s;
}
.sample5:hover span:nth-child(4){
	animation-delay:.6s;
}
.sample5:hover span:nth-child(5){
	animation-delay:.8s;
}
.sample5:hover span:nth-child(6){
	animation-delay:1s;
}
.sample5:hover span:nth-child(7){
	animation-delay:1.2s;
}
.sample5:hover span:nth-child(8){
	animation-delay:1.4s;
}
.sample5:hover span:nth-child(9){
	animation-delay:1.6s;
}
.sample5:hover span:nth-child(10){
	animation-delay:1.8s;
}











@keyframes flip{
  to{
  		transform:rotateX(360deg);
  }
}

/*Boring*/

p{
	text-align:right;
}

a{
  text-decoration:none;
  display:inline-block;
  color:black;
  border-bottom:2px solid #FFAA00;
}


            
          
!
            
              /*
    Simple jQuery image splitter. 
    You can spilt any image horizontal or vertical.

# Simple usage

You can use a number to split the image in equal parts.
  
  $().splitImage({steps : 5}) 

You can use an array to make some more advanced splitting:
    
  $().splitImage({steps : [10, 80]}

  This will split the image in 2 parts the first one will be 10% of the image width/height followed by a part 80% the image width/height.

or 

  $().splitImage({steps : [10, 80], meaning : 'px'}

This will split the image in 3 parts, too. But now the first part is 10px long followd by a part which is 80px long. The last part is the remaining width/height of the image.

# Other Settings:

## orientation

can be horizontal(default) or vertical;

## ingoreRest

the remaining part of the image will be ignored



Advanced Stuff:

$().splitImage({steps : function(){
    // Do your stuff. stop by returning undefined
}};

You can use a function callback to make you own Pattern.

*/
(function($){
    var defaults = {
        steps        : 5,   
        meaning      : 'steps',
        orientation  : 'horizontal',
        ignoreRest   :  false,
        klass        : undefined
        
    };
    
    var stepper = {
        'number' : function(steps){
            var count = 0;
            return function(){
                return (++count <= steps) ? 1 : undefined;
            }
        },
                
        'object' : function(steps){
            var cache = steps.slice();
            return function(){
                return cache.shift();
            }
        },
        
        'function' : function(steps){
            return steps;
        }
    };
 
    var calcSize = {
         'steps' : function(size, step, length){
             return (size/length);
         },
         '%'  : function(size, step){
             return (size/100) * step;
         },
         'px' : function(size, step){
             return step;
         }
    };
    
    var orientFunc = {
        'horizontal' : {
            size : function(){
                return this.width;
            },
            display : function(){
                return 'display:block;';
            }, 
            style : function(bgOffset, step){
                return 'position:absolute;left:'+bgOffset+'px;background-position:-'+bgOffset+'px 0;width:'+step+'px;height:'+this.height+'px;';
            },
            remaining  : function(bgOffset){
                return this.width-bgOffset;
            }
        },
        'vertical'   : {   
            size : function(){
                return this.height;
            },
            display : function(){
                return 'display:block;';
            }, 
            style : function(bgOffset, step){
                return 'position:absolute;top:'+bgOffset+'px;background-position:0 -'+bgOffset+'px;width:'+this.width+'px;height:'+step+'px;';
            },
            remaining  : function(bgOffset){
                return this.height-bgOffset;
            }
        }
    };

    var addBackgroundStyle = function(src, orientF){
        var klass = "split"+(+(new Date));
        $('<style>.'+klass+'{'+orientF.display()+'background-image:url('+src+ ');}</style>').appendTo($('head'));
        return klass;
    };

    var genSpan = function(klass, c){
        return '<span class="'+klass+' span'+c+'"></span>';
    };
    var genStyle = function(bgOffset, step, orientF){
        return orientF.style(bgOffset, step);
    };
    var genAttr = function(attr, value){
        return (value !== undefined) ?' '+attr+'="'+value+'" ':'';
    }
    
    var splitImage = function(img, orientF, meaning, step, size, settings){
        var klass    = addBackgroundStyle(img.attr('src'), orientF),
            spans    = '',
            spanStyle= '<style>',
            i, c = 1, bgOffset = 0;

        orientF.width    = img.width();
        orientF.height   = img.height();

        while ((i = step()) !== undefined){
            var stepInt = size(orientF.size(), i,settings.steps);
            spans += genSpan(klass, c);
            spanStyle += '.'+klass+'.span'+c+'{'+genStyle(bgOffset, stepInt, orientF)+'}';
            bgOffset += stepInt;
            c++;
        }
        var remaining = orientF.remaining(bgOffset);
        if (!settings.ignoreRest && remaining !== 0){
            spans += genSpan(klass, c);
            spanStyle += '.'+klass+' .span'+c+'{'+genStyle(bgOffset, stepInt, orientF)+'}';
        }        

        $(spanStyle+'</style>').appendTo($('head'));

        img.replaceWith($('<div'+genAttr('class',settings.klass)+' style="width:'+orientF.width+'px;height:'+orientF.height+'px;position:relative;">'+spans+'</div>')); 
    }
        

    $.fn.splitImage = function(settings){
      var settings = $.extend({}, defaults , settings || {}),
            orientF  = orientFunc[settings.orientation],
            stepType = typeof(settings.steps),  
            meaning  = ((settings.meaning === 'step' && stepType !== 'number') ? settings.meaning = '%' : settings.meaning),
            size     = calcSize[meaning];

      var split = function(img){
        				step     = stepper[stepType](settings.steps);        
            		splitImage(img, orientF, meaning, step, size, settings);   
      }
      
      $(this).each(function(){
            	var img = $(this);				
              var tmrLoaded = window.setInterval(function(){ // Ugly but working.
                if (img.width()) {
                  split(img);
                  window.clearInterval(tmrLoaded);  
                }
              }, 100);
        });
        return this;
    }

}(jQuery));
	  $('#sample1').splitImage({klass:'sample1'});
    $('#sample2').splitImage({steps:10,klass:'sample2'});
    $('#sample3').splitImage({steps:2,klass:'sample3'});
    $('#sample4').splitImage({orientation:'vertical',klass:'sample4'});

    $('#sample5').splitImage({steps:10,orientation:'vertical',klass:'sample5'});


            
          
!
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