fat / zoom.js

Medium's Image Zoom for jQuery
https://fat.github.io/zoom.js
MIT License
4.04k stars 332 forks source link

if the img is new created by js, zoom doesn`t work. Is there a solution? #85

Open weipingcui opened 7 years ago

weipingcui commented 7 years ago

if the img is new created by js, zoom doesnt work. Is there a solution? I am sorry. It works. But Just I cant find the picture on the screen. Does some one have this problem?

nishanths commented 7 years ago

It doesn't work because the listen function which registers the click handler on the images is called only once at the start. So images inserted after the page is ready will not work.

I can't think of quick fix since no global variables are exposed by the plugin.

spinningarrow commented 7 years ago

It doesn't work because the listen function which registers the click handler on the images is called only once at the start. So images inserted after the page is ready will not work.

I don't think that's completely accurate. It's true that listen is called at the start but if you see https://github.com/fat/zoom.js/blob/8dfa215d02e156f85209dd52c4c9781af2c852ec/js/zoom.js#L20 it adds an event handler for click events on <body>. Even if a new image is created dynamically, clicking on it should bubble up and everything should work.

@weipingcui can you share a JSfiddle/CodePen/equivalent example of what you're doing?