我创建了一个在台式机上运行良好的网站,但在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>
问题是图像没有立即显示,但我必须缩放页面,然后它们出现。
我假设您已经检查了输出,并且它是正确的。如果是这种情况,请尝试删除背景url:
周围的引号。body {background-image:url("images/bg'.$arrayImage[$picture].'hq.jpg");}
body {background-image:url(images/bg'.$arrayImage[$picture].'hq.jpg);}
顺便说一下,使用它们是绝对有效的,但这是非常罕见的,iOS的Webkit渲染器有时喜欢产生一些非常有bug的结果,即使有有效的标记。不幸的是,它与Android的Webkit渲染器或任何x86 Webkit引擎不同,所以如果没有非常昂贵的苹果设备,这些问题无法重现和深入检查。
使用JS,特别是使用框架(例如jQuery)完成的CSS修改通常会在需要时被智能解析,从而导致语法更正,所以这就是为什么那些引号对我来说是主要的怀疑。