玩转 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 >  
 
  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值