jackmoore / zoom

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

Destroy doesn't work #101

Closed balawton closed 8 years ago

balawton commented 8 years ago

When I run the

$('#example').trigger('zoom.destroy');

on any element e.g.:

$('#button').click('zoom.destroy');

I get the following error:

Uncaught TypeError: ((jQuery.event.special[handleObj.origType] || (intermediate value)).handle || handleObj.handler).apply is not a function(…)

jackmoore commented 8 years ago

Sorry, I couldn't reproduce this. Can you provide more information (a demo would better)? Can you reproduce this in an isolated way?

balawton commented 8 years ago

Thanks for coming back to me so quick! If you run the destroy in the console on say, one of the H3s down the side of the page on your site with the demo at the link below:

Link: http://www.jacklmoore.com/zoom/ Console: $('h3').click('zoom.destroy');

You should get the error when you click on one of the H3s e.g. 'Github Repos'. Unless I've misunderstood the selector in which case apologies!

I'm using Chrome Version 48.0.2564.103 (64-bit).

Thanks

jackmoore commented 8 years ago

Using Chrome 48 on OSX, followed your steps and was unable to reproduce the issue.

It's a suspicious error because I'm not using event delegation for the destroy event. The elements that zoom was assigned to don't contain any h3 elements, it seems unlikely that calling $('h3').trigger('zoom.destroy') would invoke any of zoom's code. Do you allow your browser addons to run in incognito mode? If not, could you try it again in incognito mode to eliminate the possibility that you have an addon that's injecting faulty script into the page? I'm a bit at a loss to explain the discrepancy.

balawton commented 8 years ago

Sure, I have tried the same in Incognito and disabled all extensions in settings and I still get the error. I've attached a screenshot of what I'm trying to do - that might be easier for you to point out whether it's an issue or me being stupid...

If all seems legit can you send me something to run in the console and I'll show you the result if I still don't get any luck?

screen shot 2016-02-09 at 14 48 34

jackmoore commented 8 years ago

Oh, I see what you are doing now. I was just thinking that the instruction $(selector).click('string') is nonsense, but that it shouldn't cause any errors. I wasn't quite sure how jQuery would handle it, but I figured that since a string isn't a valid handler jQuery wouldn't try to apply it as such... but it does.

That's how you are getting an .apply is not a function error. This is just a misunderstanding about the use of jQuery's click method, and unrelated to zoom.

jackmoore commented 8 years ago

To trigger an event, use jQuery's trigger method.

What you are doing is binding a non-valid event handler (a string, instead of a function) to the click event. This won't trigger an error on assignment, but will once a click event happens.

Does this make sense?

balawton commented 8 years ago

Gotcha - my bad. Thanks for going through that and for being so prompt!