Js弹出窗口、居中、居角、扩大窗口至屏幕最大的代码

 1. 居中弹出窗口, 并逐步扩大

  1. linenum
  2. <script type="text/javascript">
  3. //<![CDATA[
  4.     if (navigator.appName=="Microsoft Internet Explorer") {
  5.         //最大化窗口
  6.         self.moveTo(-5,-5)
  7.         self.resizeTo(screen.availWidth +8,screen.availHeight+8)
  8.         //这个脚本定义的宽度其实比原窗口还要大那么一点.
  9.     }
  10.     var w=h=200;
  11.     x=(screen.width-w)/2;
  12.     y=(screen.height-h)/2;
  13.     var n=open('','newWin','width='+w+',height='+h+',left='+x+',right='+x+',top='+y+',bottom='+y);
  14.         n.document.write('
  15.         <script>
  16.             document.write("temp"); /* 临时内容, 去掉出错 */ 
  17.             document.body.innerHTML=""; /* 清空页面内容 */ 
  18.             document.οnclick=function() /* 单击关闭窗口 */ 
  19.         </script>');
  20.         n.document.write('<h2>test moving window</h2>');
  21.         n.focus();
  22.         
  23.     var timer=setInterval('fMovingWin()',1);
  24.     
  25.     function fMovingWin(){
  26.         if (n.closed||(w>=screen.width+8&&h>=screen.height+8)) {
  27.             clearInterval(timer);
  28.             return;
  29.         }
  30.         try{
  31.             if(w<=screen.width+8)w+=2;
  32.             if(h<=screen.height+8)h+=2;
  33.             n.resizeTo(w, h)
  34.             x=(screen.width-w)/2;
  35.             y=(screen.height-h)/2;
  36.             n.moveTo(x,y)
  37.         } catch(e) {} //shawl.qiu script
  38.     }
  39. //]]>
  40. </script>

2. 居角弹出窗口, 并逐步扩大

  1. linenum
  2. <script type="text/javascript">
  3. //<![CDATA[
  4.     if (navigator.appName=="Microsoft Internet Explorer") {
  5.         //最大化窗口
  6.         self.moveTo(-5,-5)
  7.         self.resizeTo(screen.availWidth +8,screen.availHeight+8)
  8.         //这个脚本定义的宽度其实比原窗口还要大那么一点.
  9.     }
  10.     var w=h=200;
  11.     x=y=-5;
  12.     var n=open('','newWin','width='+w+',height='+h+',left='+x+',right='+x+',top='+y+',bottom='+y);
  13.         n.document.write('
  14.         <script>
  15.             document.write("temp"); /* 临时内容, 去掉出错 */   document.body.innerHTML=""; /* 清空页面内容 */ 
  16.             document.οnclick=function() /* 单击关闭窗口 */ 
  17.         </script>');
  18.         n.document.write('<h2>test moving window</h2>');
  19.         n.focus();
  20.         
  21.     var timer=setInterval('fMovingWin()',1);
  22.     
  23.     function fMovingWin(){
  24.         if (n.closed||(w>=screen.width+8&&h>=screen.height+8)) {
  25.             clearInterval(timer);
  26.             return;
  27.         }
  28.         try{
  29.             if(w<=screen.width+8)w+=2;
  30.             if(h<=screen.height+8)h+=2;
  31.             n.resizeTo(w, h)
  32.             
  33.             //从右下角逐步扩大窗口
  34. /*             x=screen.width-w
  35.             y=screen.height-h
  36.             n.moveTo(x,y) */
  37.             
  38.             //从左上角逐步扩大窗口
  39.             n.moveTo(x,y)
  40.         } catch(e) {}  //shawl.qiu script
  41.     }
  42. //]]>
  43. </script>

3. 附加: 双击滚屏, 单击停止, 以 Scroll bar 的相对位置滚屏

  1. linenum
  2. <script type="text/javascript">
  3. //<![CDATA[
  4.     function scb()
  5.     document.οnmοusedοwn=function() catch(e){} }
  6.     document.οndblclick=function()
  7. //]]> //shawl.qiu script
  8. </script>

注意: 拷贝代码后需要 查找 " ", 并替换为 "". (不加引号)
原因: CSDN 的编码器在行末自动添加空格符" ", 而这段代码正好使用 js 的 在行末作为行链接, 因此行末就是空格, 而不是 , 需要手动转正. 

  • 0
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值