Business
Jobs
  • About Us
  • Solutions
    • Job Postings
      Post your job and receive qualified candidates in 48h.
    • Candidate Assessments
      500+ technical and psychological tests, plus anti-fraud.
    • Headhunting
      Tailor-made executive search from start to finish.
    • Payroll + EOR
      Payroll dispersal and EOR across 15+ LATAM countries.
  • Pricing
  • Jobs

0

231
Views
¿El ancho de img antes de agregar a DOM?

Realicé algunas tareas de código simples y descubrí que puedo obtener el alto y el ancho de img descargado por sus atributos img.height e img.width, sin agregarlo a DOM. ¿Esto es cruzado? No se pudo encontrar ninguna información sobre este comportamiento.

about 4 years ago · Juan Pablo Isaza
1 answers
Answer question

0

Puede usar naturalWidth y naturalHeight para ese requisito. Representan la anchura y la altura originales , respectivamente, de la imagen.

naturalWidth : el ancho original de la imagen utilizada en la etiqueta.

width : el valor/valor predeterminado del atributo de ancho de la etiqueta.

naturalHeight : la altura original de la imagen utilizada en la etiqueta.

height : el valor/valor predeterminado del atributo de altura de la etiqueta.

Por ejemplo:

 let src = 'http://www.fillmurray.com/g/400/600'; let img = document.createElement('img'); img.onload = () => { console.log(`naturalWidth = ${img.naturalWidth}`); console.log(`naturalHeight = ${img.naturalHeight }`); } img.src = src;

Más información sobre naturalHeight : https://developer.mozilla.org/en-US/docs/Web/API/HTMLImageElement/naturalHeight

Más información sobre naturalWidth : https://developer.mozilla.org/en-US/docs/Web/API/HTMLImageElement/naturalWidth

about 4 years ago · Juan Pablo Isaza Report
Answer question
Find remote jobs

Discover the new way to find a job!

Top jobs
Top job categories
Business
Post vacancy Pricing Sales
Legal
Terms and conditions Privacy policy
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Show me some job opportunities
There's an error!