Reputation: 173
On my site I have multiple pictures, upon hovering on a picture jquery ought to make the image title visible via toggleClass + css, but no such luck. I'm pretty sure the problem lies in the jquery, but after numerous attempts tinkering with $this
, switching .parents
to .closest
to .parentsUntil
to etc, I've decided to seek assistance, please help I'll definitely appreciate it.
Here's a jsfiddle illustrating my the problem
Upvotes: 0
Views: 99
Reputation: 11416
I've just fixed your Fiddle
There were some issues - jquery was not included, the class imghover
was missing the closing }
, and I've adjusted the jquery select to
$(this).parents('div').find("h2").toggleClass('imghover');
As I noticed that in your Fiddle the class imghover
ends with tr
, it looks like not the complete css was copied into the original Fiddle. In first Fiddle above I've just removed this tr
and added the missing }
to close the class, so some of your intended css, e.g. transition
, could be missing. With just adding a transition - as I'd guess that something like this was intended - the adjusted second Fiddle looks better. I also removed the var $this = $(this);
as it's not needed anymore.
Upvotes: 4
Reputation: 1885
Changed CSS
.imghover {
opacity: 1;
transform: translateY(50px);
text-transform: uppercase;
font-style: italic;
transition: all 0.5s;
}
.imgtitle {
opacity: 0;
position: absolute;
color: rgba(255, 255, 255, .8);
width: 296px;
background-color: rgba(75, 85, 90, .95);
border: black solid 2px;
padding: 1.5%% 0 1.5% 0;
border-radius: 7.5px;
text-shadow: 2px 2px 1px #000;
pointer-events: none;
}
There are two points you need pay attention:
pointer-events:none
. The reason of shake is .imgtitle
node is not a child of the img.At last, when you hover the img, the transition is comfortable.
Upvotes: 1