zoom icon indicating copy to clipboard operation
zoom copied to clipboard

Zooming not moving unless mouse re-enters image

Open engelfrost opened this issue 10 years ago • 9 comments

If I initialize a zoomable image under the current cursor position, zooming does not work until I leave and the re-enter the image.

Here is an example:

$('body').on('click', function () {
    $('body').html($('#template').html()); // Adds HTML with #zoom markup
    $('#zoom').zoom();
});

http://jsfiddle.net/na4ywkfq/

I have not found a fix or a work-around yet.

engelfrost avatar Aug 29 '14 13:08 engelfrost

Sorry for the premature comment earlier, your bug was a little more complicated than I thought, though the principles are the same. When you dynamically insert the image from the template into the DOM, the image may not be loaded yet, and this will cause inconsistent behavior. You should register Zoom on the wrapper after the image.onload event is fired, and the best fix i've found (I do this with dynamically created Backbone.Views currently) is to force the deferring of the manual triggering zoom.mouseenter and zoom.mousemove events until the next event loop.

here is a working example:

http://jsfiddle.net/uz4jasp6/2/

remember your console can lie to you!

ondreian avatar Aug 29 '14 16:08 ondreian

@engelfrost Ok, that makes sense. Zoom's behavior is started on mouseenter, and ends on mouseleave, but mouseenter has already happened before zoom has been assigned to the DOM element. I'm not sure at the moment how best to check for this within the plugin, but as a temporary fix you may just be able to trigger the mouseenter event immediately after you assign zoom. Ex:

$('#zoom').zoom().trigger('mouseenter');

jackmoore avatar Aug 29 '14 17:08 jackmoore

Whoops, sorry. My comment doesn't help at all.

jackmoore avatar Aug 29 '14 17:08 jackmoore

Thanks @ondreian, you are correct about the why and how. Here is a little cleaner version of your solution: http://jsfiddle.net/uz4jasp6/3/

Zoom provides a callback method with the context (this) assigned to the image element.

jackmoore avatar Aug 29 '14 18:08 jackmoore

Thanks @jackmoore didn't know about the callback trick, definitely better than my hack

ondreian avatar Sep 01 '14 15:09 ondreian

Thank you, the callback version works fine, the first workaround only works when the image is cached.

engelfrost avatar Sep 03 '14 12:09 engelfrost

Hi guys, i have a similar problem. I load content via ajax in a div that fade in with an image inside. If mouse cursor is stucked on its, i have to exit image area and enter again to make zoom work. How to fix?

gleenk avatar Oct 25 '16 16:10 gleenk

Same here

Lucissa avatar Nov 23 '16 07:11 Lucissa

Here is a little solution: $show_img_container.zoom({url: BIG_IMAGES[i]}).trigger('mouseover')

SitanHuang avatar Jun 10 '18 22:06 SitanHuang