简体   繁体   English

如何通过视口width = device-width来获取用于加载清晰图像但正确设置字体/ div大小的设备分辨率?

[英]How get device resolution for loading sharp images but size fonts/divs properly with viewport width=device-width?

On mobile, if I don't use the tag (see below) to set the viewport width to device width, then fonts are too small and hard to read and divs size more like on a desktop. 在移动设备上,如果我不使用标签(请参见下文)将视口宽度设置为设备宽度,则字体太小且难以阅读,并且divs的大小更像在台式机上。

<meta name="viewport" content="width=device-width, initial-scale=1">

But if I use that, then choosing what size image to load will return a small, pixelated image because the reported pixel width is half what it really is. 但是,如果我使用它,那么选择要加载的大小的图像将返回一个小的像素化图像,因为报告的像素宽度是实际像素宽度的一半。 For example, an iPhone 5S will report a width of 320px when it's really showing a resolution of 640px wide. 例如,当iPhone 5S实际显示640px宽的分辨率时,它将报告320px的宽度。

How do I allow for both these differences? 如何允许这两种差异? (without the viewport tag, the css will not size properly. with it, my code loads too low a resolution image on devices that report 1 pixel width for every pixel on screen) (没有视口标签,css将无法正确调整大小。使用它,我的代码在报告屏幕上每个像素1像素宽度的设备上加载的分辨率图像太低)

I can't just double the pixel width when loading images because not every device/browser halves the pixel size. 加载图像时,我不能只是将像素宽度加倍,因为不是每个设备/浏览器都将像素大小减半。

I want the fonts and elements to be sized based on width=device-width but not the images I load. 我希望字体和元素的大小基于width=device-width而不是我加载的图像。 How do I combine these? 如何结合这些?

获取window.devicePixelRatio并将其乘以计划显示图像的宽度,以获取所需图像的实际宽度。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 iPhone视口元标记width = device-width不起作用 - iPhone viewport meta tag width=device-width not working 如果是手机,则在meta name =“ viewport”中添加“ width = device-width” - Add “width=device-width” in meta name=“viewport” if mobile phone 键“宽度”的视口参数值“device-width;”无效,并且已被忽略。注意 - Viewport argument value “device-width;” for key “width” is invalid, and has been ignored. Note that 无法识别关键点“ width”的视区参数值“ device-width;”。 内容被忽略 - Viewport argument value “device-width;” for key “width” not recognized. Content ignored 如何在Phonegap / JQuery mobile中以编程方式查找设备宽度 - How to programmatically find the device-width in Phonegap/JQuery mobile 在设备宽度上更改视口宽度 - Change viewport width on device width 如何获取媒体查询中使用的值,例如设备宽度 - How to get the values that are used in media queries, e.g. device-width 在CSS中使用设备宽度? JS的可能性? - Use device-width in CSS? JS possibilities? 使用meta标签将ipad方向检测为width = device-width - detecting ipad orientation with meta tag as width=device-width Android 2.2 2.3解决方法,用于设备宽度媒体查询 - Android 2.2 2.3 workaround for device-width media query
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM