到目前为止我有这个代码:
var img = document.getElementById('draggable');
var width = img.clientWidth;
var height = img.clientHeight;
Run Code Online (Sandbox Code Playgroud)
然而,这让我获得了html属性--css样式.我想获得文件的实际图像资源的维度.
我需要这个,因为在上传图像时,它的宽度设置为0px,我不知道为什么或发生这种情况.为了防止它,我想获得实际尺寸并重置它们.这可能吗?
编辑:即使我尝试获得naturalWidth,我也会得到0.我添加了一张图片.奇怪的是,只有当我上传新文件并刷新它才能正常工作时才会发生这种情况.
在查看光栅图像时,或多或少的所有最新Mozilla产品(例如Firefox和SeaMonkey)都将其转换为完整的HTML文档,例如:
<html>
<head>
<meta name="viewport" content="width=device-width; height=device-height;">
<link rel="stylesheet" href="resource://gre/res/ImageDocument.css">
<link rel="stylesheet" href="resource://gre/res/TopLevelImageDocument.css">
<link rel="stylesheet" href="chrome://global/skin/media/TopLevelImageDocument.css">
<title>googlelogo_color_272x92dp.png (PNG Image, 544 × 184 pixels)</title>
</head>
<body>
<img src="https://www.google.com/images/branding/googlelogo/2x/googlelogo_color_272x92dp.png" alt="https://www.google.com/images/branding/googlelogo/2x/googlelogo_color_272x92dp.png">
</body>
</html>Run Code Online (Sandbox Code Playgroud)
默认CSS样式的内容可以在此处查看:
resource://gre/res/ImageDocument.cssresource://gre/res/TopLevelImageDocument.csschrome://global/skin/media/TopLevelImageDocument.css问题在于,在HiDPI显示器上,低分辨率图像经常会放大(例如,在4k显示器上,它们放大了x1.5倍)。
为了使图像始终以其原始大小(即1:1)显示,我需要对生成的HTML应用哪些其他样式?
我正在寻找自定义userContent.css或的正确方法userChrome.css。
更多内容userChrome.css: