0

I have two images in a a tag

<a>
<img src="blabla.jpg" class="VisibleImage" />
<img src="lolo.jpg" class="HoverImage" />
</a>

by default image which have class VisibleImage is visible and HoverImage is hidden, but when someone hover over a tag then VisibleImage is hidden and HoverImage will be visible.

I am using this css:

a .VisibleImage{display:block}
a .HoverImage{display:none}

 //on hover
a:hover .VisibleImage{display:none}
a:hover .HoverImage{display:block}

But I want a animation like Slide up, I tried to use css3 but it did'nt worked. I moved to jQuery and used jQuery hover() but I failed. Please give me jQuery code

2
  • 1
    can we please see the jQuery you are attempting to use. This way we can show you where your going wrong rather than just give you an answer, Commented Sep 27, 2012 at 12:20
  • There is multiple ways you can solve this: jQueryUI (which will work cross browsers but will be a bit less smooth) or CSS3 which will work in modern browsers but not the old ones. The solution is not the same as the problem is different. So explain exactly what you want, please :) Commented Sep 27, 2012 at 12:23

2 Answers 2

1

Here you go, not sure what you want to achieve with slideUp() but this will work.

$(document).ready(function(){
    $('.HoverImage').slideUp();
$('a').bind('mouseenter', function() {
    $(this).find('.HoverImage').slideUp().fadeOut('slow', function() {
        $(this).parent().find('.VisibleImage').slideDown().fadeIn('slow');
    })
});
$('a').bind('mouseleave', function() {
    $(this).find('.VisibleImage').slideUp().fadeOut('slow', function() {
        $(this).parent().find('.HoverImage').slideDown().fadeIn('slow');
    })
});​
});

http://jsfiddle.net/shannonhochkins/QxyH3/

Cheers, Shannon

Sign up to request clarification or add additional context in comments.

2 Comments

i have multiple elements having same CSS Class, when I hover over an element all elements contain the same css shows effect, how to run this jquery for current a tag???
I've edited my comment, please if you're going to post something, post it with a greater example of what you're trying to achieve, ie an example page, a propper description..
0

use css3 transitions to get animation like slideup

.HoverImage{
  max-height:0px;
  height:auto;
  -webkit-transition: max-height 2s;
  display:none;
}

a:hover .HoverImage{
   display:block;
    max-height:500px;
}

tutorial for css3 transitions

http://www.w3schools.com/css3/css3_transitions.asp

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.