thdoan / magnify

A lightweight jQuery magnifying glass zoom plugin.
https://thdoan.github.io/magnify/
MIT License
243 stars 63 forks source link

Click Through w/o Image Map - Enhancement Idea #60

Closed marketinview closed 5 years ago

marketinview commented 5 years ago

It would be nice to have an option to turn on click through without using an image map. I was able to do it myself with an afterLoad function, but it would have been useful to have an a clickThrough option that could be set to true.

thdoan commented 5 years ago

You can add this via afterLoad event as you have done. Not enough people have asked for this, so I will not implement this for now.

jpmaradiaga commented 3 years ago

Sorry to necro this issue but I'm in need of something similar. Can anyone share and example?

marketinview commented 3 years ago

Sorry to necro this issue but I'm in need of something similar. Can anyone share and example?

I thought this feature was eventually added, but I might be imagining that.

Anyway, the following works:

var img = jQuery('img');
img.magnify({
    src: img.attr("src"),
    afterLoad: function() {
        var lens = hmi.parent(".magnify").children(".magnify-lens");
        lens.click(function(e) {
            if (e.clientX || e.clientY) {
                lens.hide();
                clickxy(e.clientX, e.clientY);
            }
        });
    }   
});

function clickxy(x, y) {
    var ev = new MouseEvent('click', {
        'view': window,
        'bubbles': true,
        'cancelable': true,
        'clientX': x,
        'clientY': y
    });
    var el = document.elementFromPoint(x, y);
    el.dispatchEvent(ev);
}