Several responses appeared here while I was writing my suggestion, but I decided to post here in the same other way as you can do the intended only using CSS.
Example in Jsfiddle: http://jsfiddle.net/pp02f40y/
.hoverInfo {
position: relative;
width: 400px;
cursor:pointer;
overflow: hidden;
font-family: sans-serif;
}
.imgInfo {
width: 400px;
}
.imgTextInfo {
position: absolute;
bottom: -30%;
width: 100%;
opacity: 0;
background: rgba(0, 0, 0, 0.8);
color: #fff;
-webkit-transition: all 0.3s ease-in-out;
-moz-transition: all 0.3s ease-in-out;
-o-transition: all 0.3s ease-in-out;
transition: all 0.3s ease-in-out;
}
.hoverInfo:hover .imgTextInfo {
opacity: 1;
bottom:0;
}
.what {padding: 5px 20px; border-bottom: 1px solid #fff;}
.when {float: right;}
.description {padding: 5px 20px;}
p {font-size: 13px;}
<div class="hoverInfo">
<img class="imgInfo" src="http://i.imgur.com/fxGRWi0.jpg"/>
<div class="imgTextInfo">
<div class="what">
<span class="title">Rihanna stuff</span>
<span class="when">May 18, 2015</span>
</div>
<div class="description">
<p>Hi there! This is just a random description. Click here to read more.</p>
</div>
</div>
</div>
Yes, this could be done with Jquery. But I personally prefer to use this option with CSS.
Here’s some advice, whenever you can use CSS instead of Jquery or javascript to do anything, use CSS. Here’s why:
First of all, using CSS is much more efficient.
You’re using a lot of unnecessary interactions to do something you can only do with CSS. And using Jquery will also increase the processing time of this action. Here’s an example:
jQuery offers a number of methods to apply specific styles, for example:
$("#meuElemento").css({
color: "#c00",
backgroundColor: "#eee",
width: "200px",
height: "100px",
borderColor: "#f00"
});
Using Pure Javascript:
var m = document.getElementById("meuElemento"), c = m.style;
c.color = "#c00";
c.backgroundColor = "#eee";
c.width = "200px";
c.height = "100px";
c.borderColor = "#f00";
More than 10,000 iterations were made using cache selectors, jQuery code ran at 6,670ms, While Native Javascript took 330ms - it was 20 times faster. Using CSS will be faster still, and it’s certainly the best way to do it unless some value needs to be calculated for some reason.
Thank you, even if you have already responded, your reply was not in vain :) After all, the code is constructive. Thank you in the same way
– Hugo Marcelo
Mister, do you know how to make the description go up? Coming from the Bottom? Like on Rihanna’s website.
– Hugo Marcelo
Yes, it is possible to do this @Hugomarcelo . Just give a negative position to the class
.imgTextInfo
as an example.imgTextInfo {bottom: -30%;}
and give you the starting position when the mouse goes over the image, which this will be.hoverInfo:hover .imgTextInfo{bottom:0;}
. Homage that we will also need to give aoverflow: hidden;
to class.hoverInfo
so that the effect is not fuzzy. See the update of my reply. If this helped you, please mark my solution as correct =)– Chun