【问题标题】:Get real width and height of website images获取网站图片的真实宽度和高度
【发布时间】:2017-08-17 21:49:24
【问题描述】:

在每个网站上都有大量超大图片。对于oversized,我的意思是真实图像的宽度和高度高于该位置,该位置可用于 HTML 和/或 CSS 规则的图像。原因是 - 图片被浏览器缩小了。

如何从网站获取具有真实尺寸和可用尺寸的图片?

【问题讨论】:

标签: html css image


【解决方案1】:

如果我正确理解您的帖子,您可以使用naturalWidthnaturalHeight 来确定图片的原始尺寸。

img = document.getElementById('image');

img.addEventListener('load', function() { 
  console.log('width', img.naturalWidth);
  console.log('height', img.naturalHeight);
});
#image {
  width: 200px;
}
<img id="image" src="http://i.imgur.com/PDE3MLe.jpg" />

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 2021-05-09
    • 2017-03-19
    • 1970-01-01
    • 2014-06-06
    • 1970-01-01
    • 2020-11-28
    • 1970-01-01
    • 2010-09-24
    相关资源
    最近更新 更多