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

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

Console