Търсене в помощните статии

Избягвайте измамите при поддръжката. Никога няма да ви помолим да се обадите или изпратите SMS на телефонен номер или да споделите лична информация. Моля, докладвайте подозрителна активност на "Докладване за злоупотреба".

Learn More

How do I get naturalWidth / naturalHeight?

  • 1 отговор
  • 1 има този проблем
  • 50 изгледи
  • Последен отговор от vrcode

more options

I believe there is a bug. I can't get naturalWidth / naturalHeight in Firefox. Neither Safari nor Chrome has this problem.

JavaScript code:

let image = document.querySelector("img"); console.log("natural width=" + image.naturalWidth + ", " + "natural height=" + image.height);

The code printed a value of 0 in Firefox whereas browsers printed the respective width and height of the image.

I believe there is a bug. I can't get naturalWidth / naturalHeight in Firefox. Neither Safari nor Chrome has this problem. JavaScript code: let image = document.querySelector("img"); console.log("natural width=" + image.naturalWidth + ", " + "natural height=" + image.height); The code printed a value of 0 in Firefox whereas browsers printed the respective width and height of the image.
Прикачени екранни снимки

Избрано решение

Edit:

solution/workaround: wait for everything to completely load by putting code in


       window.addEventListener('load', function() {
       //code
       });
Прочетете този отговор в контекста 👍 0

Всички отговори (1)

more options

Избрано решение

Edit:

solution/workaround: wait for everything to completely load by putting code in


       window.addEventListener('load', function() {
       //code
       });

Променено на от vrcode