【问题标题】:Body background images not shown on iPad and iPhoneiPad 和 iPhone 上未显示身体背景图像
【发布时间】:2013-04-19 05:32:56
【问题描述】:

我创建的网站在桌面上运行良好,但在 iPhone 和 iPad 上不显示背景图像。

我尝试删除选择图像的 php 脚本并重新编写代码以使用 javascript 设置背景,在这种情况下背景显示正确。

这是选择图像的 php 代码:

<?php
//if  doesn't exist, open the session
if(!isset($_SESSION))
{
    session_start();
}
//set coockie
setcookie("allweb","connected", time()+3600);
//if doesn' exist yet, I create a new array
if(!isset($_SESSION['arrayImage'])){
    $arrayImage = array(1,2,3,4,5,6,7,8,9,10,11,12,13,14,15);
}else{// else I get from sessiom
    $arrayImage = $_SESSION['arrayImage'];  
}
//if already exist variable $picture, increment it
if(isset($_SESSION['picture']) && isset($arrayImage)){
    $picture=$_SESSION['picture'];
    $picture = $picture + 1;
    $_SESSION['picture'] = $picture;//save picture
}else{// else I create it
    $picture = 1;
    $_SESSION['picture'] = $picture;// save it
    shuffle($arrayImage);// I shuffle the array
    $_SESSION['arrayImage'] = $arrayImage;//save array to the session
}
?>

在 php 页面中,我在样式标签之间有这段代码:

<style type="text/css">
<?php 
if($picture < 15){//if I'm not out fo bound I continue
    echo 'body {background-image:url("images/bg'.$arrayImage[$picture].'hq.jpg");}';
}
else{// else I set picture to default value and restar the loop.
    $picture = 0;
    $_SESSION['picture'] = $picture;// save it
    echo 'body {background-image:url("images/bg'.$arrayImage[$picture].'hq.jpg");}';
}       
?>      
</style>

问题是图像没有立即显示,但我必须缩放页面才能显示。

【问题讨论】:

  • 嗨,马丁,请在Stack Overflow问答中编辑您的姓名和工作单位。我可能会进来喝杯咖啡,因为我住在这条路上但我们不会在 Stack Overflow 做广告 - 如果我们这样做,则必须有免责声明。祝你好运!

标签: php iphone html css ipad


【解决方案1】:

我假设您已经检查了输出并且它是正确的。 如果是这种情况,请尝试从背景 url 周围删除引号:

body {background-image:url("images/bg'.$arrayImage[$picture].'hq.jpg");}

到

body {background-image:url(images/bg'.$arrayImage[$picture].'hq.jpg);}

顺便说一句,使用它们是绝对有效的,但这种情况非常罕见,而且 iOS 的 Webkit 渲染器有时喜欢产生一些非常错误的结果,即使使用有效的标记也是如此。不幸的是,它不同于 Android 的 Webkit 渲染器或任何 x86 Webkit 引擎,因此如果没有非常昂贵的 Apple 设备,这些问题就无法重现和深入检查。

使用 JS 完成的 CSS 修改,特别是使用框架(例如 jQuery)进行的 CSS 修改通常会被智能解析,从而在需要时进行语法更正,所以这就是为什么那些引号是我的主要怀疑对象。

【讨论】:

    猜你喜欢
    • 2013-09-30
    • 2016-09-09
    • 2014-05-16
    • 1970-01-01
    • 2017-07-27
    • 1970-01-01
    • 1970-01-01
    • 2018-01-09
    • 1970-01-01
    相关资源
    最近更新 更多