日期:2014-05-16  浏览次数:20403 次

背景图片一直要刷新
div中有一个背景图片,然后div绝对的,让后用js让层向上滚动时,为什么背景图片一直要刷新

以下是js内容调用从btnMove开始;
  <script language="javascript">

var time=null;
var moveDiv=null;
var moveHeight=30;
var clssNameNo=1;
function btnMove(messageNo){
if(time!=null){
clearTimeout(time);
}

// 初始化数据

moveDiv=document.getElementById("moveDiv");

//moveDiv.style.background="url(messageBG"+messageNo+".jpg)";
//moveDiv.style.backgroundRepeat="no-repeat";


moveDiv.style.display="block";
moveDiv.style.pixelTop=100+window.screenTop;
moveDiv.style.pixelLeft=(document.body.offsetWidth-moveDiv.offsetWidth)/2;
//moveDiv.className="a1";
moveHeight=30;
//moveDiv.style.backgroundPosition="0 30px";

clssNameNo=1;
startMove();


}
//开始移动
function startMove(){
if(time!=null){
clearTimeout(time);
}


moveDiv.style.pixelTop=moveDiv.style.pixelTop-2;
moveHeight=moveHeight-2;
time=setTimeout("startMove()",100);
if(moveHeight==0){
clearTimeout(time);
btnBeginMove();
}



}

//开始消失

function btnBeginMove(){
time=setTimeout("beginMove()",2000);
}
function beginMove(){
//moveDiv.style.backgroundPosition="0 -20px";
moveDiv.style.display="none";
}


  </script>

------解决方案--------------------
在js里加上这句试试
JScript code

if(document.execCommand){
    document.execCommand("BackgroundImageCache", false, true);
}

------解决方案--------------------
准确的说是这样的,每次你移动的话,会调用onrisize函数,而且每次这个局部的标签会重新加载所有的内容,包括背景
------解决方案--------------------
div 是html元素
img是html标签 不一样的