jackmoore / wheelzoom

A small script for zooming IMG elements with the mousewheel/trackpad.
http://www.jacklmoore.com/wheelzoom
MIT License
342 stars 95 forks source link

load() fails to retrieve image width and height correctly when styling images with CSS #37

Open edtamarin opened 5 years ago

edtamarin commented 5 years ago

I have a web page where several images are rendered in a tabbed view. On page load the image in the default tab is being processed correctly. However, when the tab is switched, the width and height values are corrupted, with width returning 80 and height returning NaN.

I suspect the issue might arise from the fact that my images have no explicit width and height tag; rather, width and height are defined in CSS using width:80%; height: auto'. The return values from the CSS resemble the corrupted ones (80% andauto-> 80 andNaN. Perhaps thegetComputedStyle` function cannot parse the values correctly.

This is supported by the fact that when I declared width and height explicitly in the img tag, the issue went away.