【问题标题】:Background Image -- Chrome Dev Tools Mobile Emulator Doesn't Match Actual Device (iPhone)背景图片 - Chrome 开发工具移动模拟器与实际设备 (iPhone) 不匹配
【发布时间】:2015-10-08 20:10:53
【问题描述】:

奇怪的问题:我正在开发一个引导响应站点,并使用 Chrome 开发者工具设备模拟器来查看情况。不幸的是,我在 Chrome Devtools 上看到的和我在实际手机上看到的完全不同。

由于某种原因,我的背景图片没有正确传播。该主页的五张幻灯片中的四张都注明了该缺陷。

<div id="slide-2m" class="gf_mobile" style=" height: 100%; margin: 0 auto; 
            overflow: hidden; background-color: white;
            background-image: url(<?php echo get_stylesheet_directory_uri(); ?>/includes/images/oranges_mobile.png);
            background-repeat: no-repeat; background-position: center bottom; background-attachment: fixed; padding: 40px 0;" >
    <div style="height: 100%; overflow: hidden; margin-top: 20%;" >
        <img src="<?php echo get_stylesheet_directory_uri(); ?>/includes/images/who_we_are_text_883x862.png" style="width: auto; height: 55vh;">
    </div>
    <div style="height: 100%; overflow: hidden; margin-top: -300px;">
        <img src="<?php echo get_stylesheet_directory_uri(); ?>/includes/images/sqf_logo_883x862.png" style="width: auto; height: 55vh; ">
    </div>
</div>

嗯..我想知道它是使用 vh (视口单位?)还是双重使用 background-color: white;和背景图像:(我使用的是透明背景的.png,所以我需要那里的白色。)?

那么显而易见的问题是,为什么模拟器不能准确匹配实际的移动设备?这是 Chrome 开发者工具中的错误吗?

啊啊啊啊啊!我刚刚使用带有 Chrome 浏览器的三星 Galaxy S5 测试了同一个站点,它看起来与 Chrome 浏览器模拟器相同。完美的!那么……这是否意味着 Chrome 在其 iPhone 模拟器的细节上出错了(或者……Apple 有过错吗?)

注意:是的,我知道涉及移动(视觉视口与布局视口)的问题参考:A Tale of Two Viewports.

我将尝试将所有 vh 和 vw 转换为像素,然后重新测试。但我仍然对为什么模拟器中的差异感到困惑。再说一遍,这应该是一个错误提交吗?提交给谁...... Apple 或 Chrome 的人?

更新:我正在努力将所有 VW 和 VH 转换为像素,但到目前为止,在逐个屏幕的基础上,这是失败的。我真的认为这与 CSS 和背景大小和背景位置有关。看看这张幻灯片上的背景图片,模拟器 vs iphone。

<div id="slide-4m"  class="gf_mobile" style=" height: 100%; margin: 0 auto; overflow: 
            hidden; background-color: white;
            background-image: url(<?php echo get_stylesheet_directory_uri(); ?>/includes/images/farm_field_1018x474.jpg);
            background-repeat: no-repeat; background-position: center center; background-attachment: fixed; 
            background-size: cover; padding: 40px 0;" >

我刚刚注意到的另一件事:我已经设置了background-attachment: fixed;,这就是它们在模拟器上的工作方式。在三星上,我可以看到所有五张幻灯片的背景,但它们会滚动。在 iPhone 上,我看不到大多数幻灯片的背景。整件事很奇怪。

哎呀:Background-fixed, not so hot on mobile...

【问题讨论】:

    标签: css iphone google-chrome google-chrome-devtools


    【解决方案1】:

    呃。答案是不要将background-attachment: fixed; 用于移动设备。

    参考:How to replicate background-attachment fixed on iOSFixed background image with ios7

    嗯.. 开发工具模拟器是否应该在该主题上为您提供帮助?这应该是向 Google Chrome 团队推荐的功能吗?

    【讨论】:

    • 我不认为 Chrome 可以真正模拟所有的怪癖。我建议使用 Xcode 附带的 iOS Simulator 来测试 iPhone,它附带的 Safari 版本几乎可以模拟所有问题。您仍然需要在真实设备上进行测试,并且有些东西不是模拟的(例如内存限制)。
    【解决方案2】:

    iPhone 上的 Safari 对图像有一定的大小限制(JPG 最大 32 兆像素,GIF/PNG 3-5 兆像素,具体取决于设备)。

    您可以尝试使用不同的、更小(分辨率)的图像作为背景图像吗?

    【讨论】:

    • 我可以试试。 oranges_mobile.png 为 640K 大,768 x 823 像素。页面上没有一个图像大于 2 Meg,尽管有很多 'em.. 都在 display: none; 包装器中。我会说,有一件奇怪的事情。我在 iPhone 上使用 Chrome。我有一个用于故障排除的附加工具。它显示浏览器大小和浏览器 ID.. 在带有 Chrome 浏览器的 iphone 上,它显示“safari”是谷歌和苹果必须在 iphone 中启用 chrome 浏览器的一些妥协吗?
    • 那么可能是图片数量,总量也有限制。是的,iPhone 上的 Chrome 使用 Safari 的渲染引擎(App Store 的合同义务)。
    猜你喜欢
    • 1970-01-01
    • 2018-09-14
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2023-04-06
    • 1970-01-01
    • 2020-03-19
    相关资源
    最近更新 更多