2011-07-09 17 views
1

我想爲加載其源頁面的I幀設置動畫。我部分地用JavaScript代碼來實現我的目標是這樣的如何刷新加載圖像的iframe url顯示

function reloadIt() 
{ 
    frm=document.getElementsByName("pagers")[0];  //we get the iframe object 
    frm.src=frm.src;  //or you can set the src to a new src 
    setTimeout("reloadIt()",100000);   //the function will run every 60000 miliseconds, or 60 seconds 
} 

和我的HTML正文代碼放在這裏

<body onload="reloadIt()"> 

和我的IFRAME代碼是這樣

<div id="divLoading"> 
    <div style="width:100%; height:200px; align="center"> 
     <img src="loader.gif" alt="" align="absmiddle"/> 
    </div> 
</div> 
<div id="divFrameHolder" style="display:none"> 
    <iframe src="lead.php" height="450px;" width="100%" name="pagers" onload="hideLoading()" > </iframe>` 
</div> 

這個作品當這個html頁面第一次加載的時候很好,我們可以看到在Iframe中加載Image直到它的源頁面加載。但在IFrame刷新的時間間隔後沒有加載圖像,它只是簡單地重新加載其源頁面...任何機構可以幫助我?

回答

0

你可以看看BlockUi,一個jQuery插件。 (http://jquery.malsup.com/block/#element)。試試這樣:

function reloadIt() { 
     $("#iframeholder").block({ 
      message: '<img src="css/ajax-loader.gif"/>', 
      css: { width: "600px;", height: "400px;" } 
     }); 
     $('#pagers').attr('src', $('#pagers').attr("src")); 
     $('#iframeholder').unblock() 
     setTimeout("reloadIt()", 5000); 
} 
+0

如果這很有用,請將其標記爲答案 – Eonasdan