當(dāng)前位置:軟件學(xué)堂 > 資訊首頁 > 網(wǎng)絡(luò)編程 > 編程其他 > JS代碼實現(xiàn)窗口慢慢變大

JS代碼實現(xiàn)窗口慢慢變大

2012/11/3 16:04:08作者:佚名來源:網(wǎng)絡(luò)

移動端

【實例名稱】

JS代碼實現(xiàn)窗口慢慢變大

【實例描述】

窗口打開時可以使用一些特效,如卷簾式、默認(rèn)最大化等。本例通過window.resizeTo方法實現(xiàn)創(chuàng)建窗口逐漸變大的效果。

【實例代碼】

<html xmlns="http://www.w3.org/1999/xhtml" > <head> <title>標(biāo)題頁-學(xué)無憂(www.wangbatian.cn)</title> <script language="javascript">     var Windowsheight=100;     var Windowswidth=100;     var numx=5;  function openwindow(thelocation){       temploc=thelocation;     if (!(window.resizeTo&&document.all)&&! (window.resizeTo&&document.getElementById))   {            window.open(thelocation);   //打開新窗口       return ;  }         windowsize=window.open("","","scrollbars");      windowsize.moveTo(0,0);     //移動窗口到0,0坐標(biāo)處      windowsize.resizeTo(100,100); //改變窗口大小    tenumxt();   }     function tenumxt(){        if (Windowsheight>=screen.availHeight-3) //高度超過窗體最大高度時         numx=0 ;       windowsize.resizeBy(5,numx);       Windowsheight+=5;     //高度逐次加5     Windowswidth+=5;      //寬度逐次加5      if (Windowswidth>=screen.width-5)  {  //寬度超過窗體最大寬度時         windowsize.location=temploc                Windowsheight=100             Windowswidth=100                  numx=5                  return           }         setTimeout("tenumxt()",50)         //通過計時器,逐漸變大窗口     }   </script>

</head> <body> <a href="javascript:openwindow('http://www.google.com')">進入搜索</a> </body> </html>

【運行效果】

 慢慢變大的窗口運行效果

【難點剖析】

本例的重點是window對象的方法:“mOveTo”和“resizeTo”?!癿oveTo”表示移動窗口到指定位置,其包含兩個參數(shù),分別代表目標(biāo)點的x和y坐標(biāo)?!皉esizeTo”表示改變窗口的大小,其包含兩個參數(shù),分別代表窗口的高度和寬度。

【源碼下載】

為了JS代碼的準(zhǔn)確性,請點擊:慢慢變大的窗口 進行本實例源碼下載