玩轉 Javascript 彈出窗口, 居中與居角擴大窗口至屏幕最大值

玩轉 Javascript 彈出窗口, 居中與居角擴大窗口至屏幕最大值 By shawl.qiu

說明:
主要使用 Js 的 setInterval() 和 clearInterval() 函數完成操作.

目錄:
1. 居中彈出窗口, 並逐步擴大
2. 居角彈出窗口, 並逐步擴大
3. 附加: 雙擊滾屏, 單擊停止, 以 Scroll bar 的相對位置滾屏

shawl.qiu 
2006-10-24
http:
//blog.csdn.net/btbtd

1. 居中彈出窗口, 並逐步擴大

linenum 
<script type="text/javascript"> 
//<![CDATA[ 
    if (navigator.appName=="Microsoft Internet Explorer"
        
//最大化窗口 
        self.moveTo(-5,-5
        self.resizeTo(screen.availWidth 
+8,screen.availHeight+8
        
//這個腳本定義的寬度其實比原窗口還要大那麼一點. 
    }
 
  
    
var w=h=200
    x
=(screen.width-w)/2
    y
=(screen.height-h)/2
    
var n=open('','newWin','width='+w+',height='+h+',left='+x+',right='+x+',top='+y+',bottom='+y); 
        n.document.write(
' 
        <script> 
            document.write("temp"); /* 臨時內容, 去掉出錯 */  
            document.body.innerHTML=""; /* 清空頁面內容 */  
            document.οnclick=function(){ close();} /* 單擊關閉窗口 */  
        </script>
'); 
        n.document.write(
'<h2>test moving window</h2>'); 
        n.focus(); 
         
    
var timer=setInterval('fMovingWin()',1); 
     
    
function fMovingWin()
        
if (n.closed||(w>=screen.width+8&&h>=screen.height+8)) 
            clearInterval(timer); 
            
return
        }
 
        
try
            
if(w<=screen.width+8)w+=2
            
if(h<=screen.height+8)h+=2
            n.resizeTo(w, h) 
            x
=(screen.width-w)/2
            y
=(screen.height-h)/2
            n.moveTo(x,y) 
        }
 catch(e) {} //shawl.qiu script 
    }
 
  
//]]> 
</script> 

2. 居角彈出窗口, 並逐步擴大

linenum 
<script type="text/javascript"> 
//<![CDATA[ 
    if (navigator.appName=="Microsoft Internet Explorer"
        
//最大化窗口 
        self.moveTo(-5,-5
        self.resizeTo(screen.availWidth 
+8,screen.availHeight+8
        
//這個腳本定義的寬度其實比原窗口還要大那麼一點. 
    }
 
  
    
var w=h=200
    x
=y=-5
    
var n=open('','newWin','width='+w+',height='+h+',left='+x+',right='+x+',top='+y+',bottom='+y); 
        n.document.write(
' 
        <script> 
            document.write("temp"); /* 臨時內容, 去掉出錯 */  
            document.body.innerHTML=""; /* 清空頁面內容 */  
            document.οnclick=function(){ close();} /* 單擊關閉窗口 */  
        </script>
'); 
        n.document.write(
'<h2>test moving window</h2>'); 
        n.focus(); 
         
    
var timer=setInterval('fMovingWin()',1); 
     
    
function fMovingWin()
        
if (n.closed||(w>=screen.width+8&&h>=screen.height+8)) 
            clearInterval(timer); 
            
return
        }
 
        
try
            
if(w<=screen.width+8)w+=2
            
if(h<=screen.height+8)h+=2
            n.resizeTo(w, h) 
             
            
//從右下角逐步擴大窗口 
/*             x=screen.width-w 
            y=screen.height-h 
            n.moveTo(x,y) 
*/
 
             
            
//從左上角逐步擴大窗口 
            n.moveTo(x,y) 
        }
 catch(e) {}  //shawl.qiu script 
    }
 
  
//]]> 
</script> 

3. 附加: 雙擊滾屏, 單擊停止, 以 Scroll bar 的相對位置滾屏

linenum 
<script type="text/javascript"> 
//<![CDATA[ 
    function scb(){ timer=setInterval('scrollBy(0,1)',1000) } 
    document.onmousedown
=function()try{ clearInterval(timer);} catch(e){} } 
    document.ondblclick
=function(){ scb(); } 
//]]> //shawl.qiu script 
</script> 
 
發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章