简体   繁体   中英

When dividing resolutions in javascript i get NaN

Hello i was working on this script where is calculated the ratio of the resolution of the screen or an image. Whenever an image didn't have a normal resolution or i tried it with the view-port resolution it would be NaN .

Example (y is an image) :

y.offsetWidth / y.offsetHeight = NaN

I tried numerous ways on the internet to fix this but i couldn't does anyone know wow to?

Perhaps what you want is something like

y.offsetWidth / y.offsetHeight

As nicovank mentioned, there is no offsetLength property.

you will get NaN whenever you try to do arithmetic calculation on something which are not number or cant be parsed to valid number. Here, both y.offsetLength and y.offsetheight are undefined (because no such properties in JS) and hence yields to NaN when you try to do divition operation on them. Use offfsetHeight and offsetWidth instead.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM