0

I would like to know if there is a way to show the same image as you are hovering, with a different size, next to the cursor? And on mouseout, it should disappear.

2
  • 5
    Yes there's a way. It's not really hard either. What have you tried so far? So you have any markup already? Or were you just planning to ask if it was possible, cause it is. Commented Feb 28, 2012 at 8:48
  • Hope the community will not be angry with me, for answering this question. Commented Feb 28, 2012 at 8:57

3 Answers 3

5

Something like this will work. Adjust to your needs. http://jsfiddle.net/elclanrs/jF27b/

var $img = $('img');
$img.hide();
$('div').mousemove(function(e) {
    $img.stop(1, 1).fadeIn();
    $('img').offset({
        top: e.pageY - $img.outerHeight(),
        left: e.pageX - $img.outerWidth()
    });
}).mouseleave(function() {
    $img.fadeOut();
});
Sign up to request clarification or add additional context in comments.

2 Comments

Change mouseout to mouseleave to get rid of mild flickering if hovering over the image (moving cursor up and left)
Yes, mouseout is fired when the mouse is out of the element, which at the time of hovering over img, it is out of div. mouseleave on the other hand is when the mouse leaves the element and takes child elements into consideration. So since img is inside of div the event isn't fired.
0

I believe this is what you want.

http://jsfiddle.net/BaDCe/

Comments

0

Here is a simple way you can do it.

Markup Structure

<li class="thumb">
    <img class="small" src="http://stackoverflow.com/" />
    <img class="large" src="someimage.jpg" />
</li>

jQuery Snippet

$(".thumb").mouseover(function() {    
   $(this).children(".large").show();
}).mouseout(function() {
   $(this).children(".large").hide();
});

P.S: I am not going to test this code to work, because I completely agree with @OptimusCrime

Demo

1 Comment

I have to be honest, it's noble that you promote that cause, but it's better not to provide an answer than to provide one that's untested and potentially worthless.

Your Answer

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

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.