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.
-
5Yes 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.OptimusCrime– OptimusCrime2012-02-28 08:48:55 +00:00Commented Feb 28, 2012 at 8:48
-
Hope the community will not be angry with me, for answering this question.Starx– Starx2012-02-28 08:57:07 +00:00Commented Feb 28, 2012 at 8:57
Add a comment
|
3 Answers
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();
});
2 Comments
Adam Merrifield
Change
mouseout to mouseleave to get rid of mild flickering if hovering over the image (moving cursor up and left)Adam Merrifield
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.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
Purag
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.