Simple Image Hover Effect with jQuery and CSS/CSS3

File Size: 2.38 KB
Views Total: 9135
Last Update:
Publish Date:
Official Website: Go to website
License: MIT
   
Simple Image Hover Effect with jQuery and CSS/CSS3

A simplest way to create a CSS3 animated, customizable overlay effect when users hovers over an element. jQuery is used only to make the overlay open / close on hover by toggling CSS classes.

How to use it:

1. Create an overlay element for the container 'content' following the markup structure like this:

<div class="content"> 
  <a class="box overlay" href="#"> 
    <span class="image-caption">Image Caption</span> 
    <span class="desc overlay-toggle">
      More description here
      <span class="see-more">See more...</span>
    </span> 
  </a> 
</div>

2. Style the overlay.

.box {
  display: inline-block;
  width: 370px;
  height: 270px;
  transition: all ease-in 0.3s;
}

.box:hover { background-color: rgba(0,0,0, 0.5); }

.box:hover .image-caption {
  background-color: transparent;
  margin-top: 40px;
}

.image-caption {
  position: absolute;
  display: inline-block;
  width: 370px;
  text-align: center;
  padding: 20px 0;
  color: #ffffff;
  text-transform: uppercase;
  font-family: Helvetica, Arial, sans-serif;
  font-size: 20px;
  text-shadow: 0px 2px 2px rgba(0,0,0,0.8);
  margin-top: 207px;
  background-color: rgba(0,0,0,0.7);
  transition: all ease-in 0.3s;
}

.desc {
  position: absolute;
  width: 370px;
  margin-top: 150px;
  text-decoration: none;
  text-align: center;
  font-family: Georgia, serif;
  font-style: italic;
  font-size: 14px;
  line-height: 1.4;
  color: transparent;
  text-shadow: 0px 2px 2px rgba(0,0,0,0);
  transition: all ease-in 0.3s;
}

.see-more { text-decoration: underline; }

3. Add a background image to the 'content'

.content {
  display: inline-block;
  width: 370px;
  height: 270px;
  background: url(bg.jpg) no-repeat;
  background-size: 370px 270px;
}

4. Customize the CSS styles of your overlay on mouse hover.

.on {
  color: #ffffff;
  text-shadow: 0px 2px 2px rgba(0,0,0,0.8);
}

5. Apply the 'on' CSS class to the overlay on hover. Insert the following JavaScript snippet after jQuery library and we're done.

$(".overlay").hover(
  function() {
    $(".overlay-toggle").toggleClass("on");
  }
);

This awesome jQuery plugin is developed by thomashardy. For more Advanced Usages, please check the demo page or visit the official website.