首页 | 站长技术 专题 | 下载频道 | 网页模板 | 图片素材 | 虚拟主机 | 项目市场 | 源码市场 | 本站产品 | 广告服务 | 建站论坛
文档首页
建站指南
网站编程
网站设计
图像动画
网络安全
服务器技术
数据库技术
技术专题
技术问答
您的位置:中国建站 > 站长技术 > 网站编程 > Javascript > 玩转 Javascript 弹出窗口, 居中与居角扩大窗口至屏幕最大值

玩转 Javascript 弹出窗口, 居中与居角扩大窗口至屏幕最大值

加入时间:2006-12-24
说明:
主要使用 Js 的 setInterval() 和 clearInterval() 函数完成操作.

目录:
1. 居中弹出窗口, 并逐步扩大
2. 居角弹出窗口, 并逐步扩大
3. 附加: 双击滚屏, 单击停止, 以 Scroll bar 的相对位置滚屏

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

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

2. 居角弹出窗口, 并逐步扩大
    linenum
  1. <script type="text/javascript">
  2. //<![CDATA[
  3.     if (navigator.appName=="Microsoft Internet Explorer") {
  4.         //最大化窗口
  5.         self.moveTo(-5,-5)
  6.         self.resizeTo(screen.availWidth +8,screen.availHeight+8)
  7.         //这个脚本定义的宽度其实比原窗口还要大那么一点.
  8.     }
  9.     var w=h=200;
  10.     x=y=-5;
  11.     var n=open('','newWin','width='+w+',height='+h+',left='+x+',right='+x+',top='+y+',bottom='+y);
  12.         n.document.write('\
  13.         <script>\
  14.             document.write("temp"); /* 临时内容, 去掉出错 */ \
  15.             document.body.innerHTML=""; /* 清空页面内容 */ \
  16.             document.onclick=function(){ close();} /* 单击关闭窗口 */ \
  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 的相对位置滚屏
    linenum
  1. <script type="text/javascript">
  2. //<![CDATA[
  3.     function scb(){ timer=setInterval('scrollBy(0,1)',1000) }
  4.     document.onmousedown=function(){ try{ clearInterval(timer);} catch(e){} }
  5.     document.ondblclick=function(){ scb(); }
  6. //]]> //shawl.qiu script
  7. </script>
上一篇文章:如何用javascript控制上传文件的大小?
下一篇文章:javascript 简单高效判断数据类型 系列函数
返回上页】 
 

本站在线服务QQ  程序定制:70632246 广告受理/投搞/投诉:7606208 技术客服:3828351
网站简介 广告服务 成功案例 联系方式 办公电话:0580-3825369
Copyright © 2001-2007 JZ173.COM,All rights reserved  浙ICP备05023962号 感谢【中国商务网】提供服务器