jackmoore / zoom

jQuery plugin for zooming images on mouseover.
http://www.jacklmoore.com/zoom/
MIT License
1.54k stars 460 forks source link

Allow elements to be clicked that must reside on top of a zoom element #125

Closed ghost closed 7 years ago

ghost commented 7 years ago

It's very common to have elements to be on top of an element that has a zoom, but say an absolute element sits top of the zoomed element and its in the same container, the zoom is always triggered when you try to click the element that sits on top.

Is there anyway to allow jquery access to an element that sits on top and in the same container, instead of the zoom being triggered.

jackmoore commented 7 years ago

I understand what you are asking for, but this isn't a feature I'm interested in supporting. If you want to modify zoom to support what you are doing, you'll need to do a couple of things.

In the event handler, add a condition to short circuit the event handler if the target of the event is not the same as the zoomed img element. For example, this:

$source.on('click.zoom',
    function (e) {
        // code
    }
);

Would change to this:

$source.on('click.zoom',
    function (e) {
        if (e.target !== img) return;
        // code
    }
);

Then you'll also need to give your absolutely positioned element a z-index so that it sits above the zoomed img element.

ghost commented 7 years ago

The two blocks of code above are identical.

Generally this isn't good UX practice for the zoom to simply shut out all elements that are absolutely positioned atop the image, but I appreciate the plugin for sure.

jackmoore commented 7 years ago

Fixed the code block.