Pen ID
Unlock Campus Themeforest adv



body {
  background-color: #4C4C4C;

.container {
  font-size: 0;
  width: 100%;
  margin-top: 50px;
  text-align: center;

.card {
  overflow: hidden;
  position: relative;
  display: inline-block;
  height: 400px;
  width: 600px;
  Each "card" is set to 600x400px because that is the size of  the image, adjust as needed. Make sure the overflow is set to hidden or else when the img scales it will clip with the other images.

.img-container {
  transition: transform .1s ease;

.img-container:hover {
  transform: scale(1.1);
  Change the scale value as much as you want to change the amount of zoom on hover.

.card img {
  opacity: .5;
  transform: translate(0,0);
  Change the opacity value to change how "faded" you want the image to appear when it is not hovered.
  transition: opacity .25s ease-in-out;

.card img:hover {
  opacity: 1;
//Creates an event that fires every time the mouse moves over any div with the class of "img".
  //Both the x and y value are calculated by taking the mouse x,y position on the page and subtracting it from the x,y position of the image on the page. "this" is the hovered element with the class of "img"
  var mousex = event.pageX - $(this).offset().left;
  var mousey = event.pageY - $(this).offset().top;
  //If you just used the mouse position values the translation effect will only go up and to the right, by subtracting half of the length / width of the imagevfrom the values  we get either a positive or negitive number so that the image will move in any direction.
  //The 40 controls the amount of "movement" that will happen by giving us a smaller number, feel free to change it to get the effect that you want.
  var imgx = (mousex - 300) / 40;
  var imgy = (mousey - 200) / 40;
  //Adds a translation css styles to the image element
  $(this).css("transform", "translate(" + imgx + "px," + imgy + "px)");

//This function will fire every time the user mouses off of the image. It resets the translation back to 0.
  $(this).css("transform", "translate(0px,0px)");
Host Instantly Drag and Drop Website Builder



Mouse hover effect that tracks the users mouse and moves the image along with it.
Mon, 11/27/2017 - 21:40

Related Codes

Pen ID
Pen ID
Pen ID