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.

            
              <div class="gallery">
      <ul>
        <li>
            <a href="http://pixabay.com/en/birkenau-auschwitz-concentration-402324/" title="Birkenau" target="_blank">
                <img src="http://www.8bit-code.com/demos/direction-aware-hover-image-gallery/img/image.jpg" alt="" />
                <div class="info"><h1 class="title">Birkenau</h1></div>
            </a>
        </li>
        <li>
            <a href="http://pixabay.com/en/black-and-white-railway-bridge-50272/" title="Black And White Railway Bridge Railway Bridge" target="_blank">
                <img src="http://www.8bit-code.com/demos/direction-aware-hover-image-gallery/img/image1.jpg" alt="" />
                <div class="info"><h1 class="title">Railway Bridge</h1></div>
            </a>
        </li>
        <li>
            <a href="http://pixabay.com/en/railway-black-and-white-301155/" title="Locomotive" target="_blank">
                <img src="http://www.8bit-code.com/demos/direction-aware-hover-image-gallery/img/image2.jpg" alt="" />
                <div class="info"><h1 class="title">Locomotive</h1></div>
            </a>
        </li>
        <li>
            <a href="http://pixabay.com/en/oldtimer-car-old-vintage-headlight-166530/" title="Oldtimer" target="_blank">
                 <img src="http://www.8bit-code.com/demos/direction-aware-hover-image-gallery/img/image3.jpg" alt="" />
                 <div class="info"><h1 class="title">Oldtimer</h1></div>
            </a>
        </li>
        <li>
            <a href="http://pixabay.com/en/read-book-reading-literature-books-369040/" title="Literature" target="_blank">
                <img src="http://www.8bit-code.com/demos/direction-aware-hover-image-gallery/img/image4.jpg" alt="" />
                <div class="info"><h1 class="title">Literature</h1></div>
            </a>
        </li>
        <li>
            <a href="http://pixabay.com/en/roses-flower-love-black-white-66517/" title="Roses" target="_blank">
                 <img src="http://www.8bit-code.com/demos/direction-aware-hover-image-gallery/img/image5.jpg" alt="" />
                 <div class="info"><h1 class="title">Roses</h1></div>
            </a>
        </li>
        <li>
            <a href="http://pixabay.com/en/dandelion-wind-blown-seeds-333093/" title="Dandelion" target="_blank">
                 <img src="http://www.8bit-code.com/demos/direction-aware-hover-image-gallery/img/image6.jpg" alt="" />
                 <div class="info"><h1 class="title">Dandelion</h1></div>
            </a>
        </li>
        <li>
            <a href="http://pixabay.com/en/eiffel-tower-paris-seine-riverside-349819/" title="Eiffel Tower" target="_blank">
                 <img src="http://www.8bit-code.com/demos/direction-aware-hover-image-gallery/img/image7.jpg" alt="" />
                 <div class="info"><h1 class="title">Eiffel Tower</h1></div>
            </a>
        </li>
        

      </ul>
    </div><!-- .gallery -->
            
          
!
            
              * {
  margin: 0;
  padding: 0;
  -webkit-box-sizing: border-box;
     -moz-box-sizing: border-box;
          box-sizing: border-box;
}

.gallery {
	width: 100%;
	height: auto;
}

.gallery li {
	width: 25%;
	position: relative;
	float: left;
	overflow: hidden;
}

.transform {
	-webkit-transition: all .25s cubic-bezier(.2, .31, .36, 1);
       -moz-transition: all .25s cubic-bezier(.2, .31, .36, 1);
	     -o-transition: all .25s cubic-bezier(.2, .31, .36, 1);
	        transition: all .25s cubic-bezier(.2, .31, .36, 1);
}

.gallery a {
	width: 100%;
	height: 100%;
	display: block;
}

.gallery img {
	position: relative;
    width: auto\9;
    height: auto;
    max-width: 100%;
    vertical-align: middle;
    border: 0;
    -ms-interpolation-mode: bicubic;
    -webkit-backface-visibility: hidden;
    -webkit-transform: translateZ(0);
    transform: translateZ(0);
}

.gallery .info {
	width: 100%;
	height: 100%;
	position: absolute;
	z-index: 10;
	background: #B1C5F0;
    text-align: center;
    font-family: "Helvetica Neue", Helvetica, Arial, sans-serif;
    -webkit-transform: translateZ(0);
   	        transform: translateZ(0);
}

.gallery .title {
	font-weight: bold;
	font-size: 20px;
    color: rgb(43, 43, 43);
    position: relative;
    top: 45%;
}
            
          
!
            
              //Direction aware image gallery effect
//created by http://8bit-code.com
//tutorial at http://www.8bit-code.com/tutorials/direction-aware-image-gallery-effect

$(function () {
  $(".gallery li").on("mouseenter mouseleave", function(e){

/** the width and height of the current div **/
var w = $(this).width();
var h = $(this).height();

/** calculate the x and y to get an angle to the center of the div from that x and y. **/
/** gets the x value relative to the center of the DIV and "normalize" it **/
var x = (e.pageX - this.offsetLeft - (w/2)) * ( w > h ? (h/w) : 1 );
var y = (e.pageY - this.offsetTop  - (h/2)) * ( h > w ? (w/h) : 1 );

/** the angle and the direction from where the mouse came in/went out clockwise (TRBL=0123);**/
/** first calculate the angle of the point, 
 add 180 deg to get rid of the negative values
 divide by 90 to get the quadrant
 add 3 and do a modulo by 4  to shift the quadrants to a proper clockwise TRBL (top/right/bottom/left) **/
var direction = Math.round((((Math.atan2(y, x) * (180 / Math.PI)) + 180 ) / 90 ) + 3 )  % 4;

  

/** check for direction **/ 
switch(direction) {
 case 0:
  // direction top
  var slideFrom = {"top":"-100%", "right":"0"};
  var slideTo = {"top":0};

  var imgSlide = "0, 60";
 break;
 case 1: //
  // direction right
  var slideFrom = {"top":"0", "right":"-100%"};
  var slideTo = {"right":0};

  var imgSlide = "-60, 0";
 break;
 case 2:
  // direction bottom
  var slideFrom = {"top":"100%", "right":"0"};
  var slideTo = {"top":0};

  var imgSlide = "0, -60";
  break;
 case 3:
  // direction left
  var slideFrom = {"top":"0", "right":"100%"};
  var slideTo = {"right":0};

  var imgSlide = "60, 0";
 break;
}



    if( e.type === 'mouseenter' ) {

      var element = $(this);

      element.find(".info").removeClass("transform").css(slideFrom);
      element.find("img").addClass("transform").css("transform","matrix(1, 0, 0, 1,"+imgSlide+")");

      setTimeout(function(){
        element.find(".info").addClass("transform").css(slideTo);
      },1);


    }else {

      var element = $(this);

      element.find(".info").addClass("transform").css(slideFrom);
      element.find("img").removeClass("transform").css("transform","matrix(1, 0, 0, 1,"+imgSlide+")");

      setTimeout(function(){
        element.find("img").addClass("transform").css("transform","matrix(1, 0, 0, 1,0,0)");
      },1);

    }

});

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