`

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

 
阅读更多

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

    linenum
  1. <scripttype="text/javascript">
  2. //<![CDATA[
  3. if(navigator.appName=="MicrosoftInternetExplorer"){
  4. //最大化窗口
  5. self.moveTo(-5,-5)
  6. self.resizeTo(screen.availWidth+8,screen.availHeight+8)
  7. //这个脚本定义的宽度其实比原窗口还要大那么一点.
  8. }
  9. varw=h=200;
  10. x=(screen.width-w)/2;
  11. y=(screen.height-h)/2;
  12. varn=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()/*单击关闭窗口*/
  18. </script>');
  19. n.document.write('<h2>testmovingwindow</h2>');
  20. n.focus();
  21. vartimer=setInterval('fMovingWin()',1);
  22. functionfMovingWin(){
  23. if(n.closed||(w>=screen.width+8&&h>=screen.height+8)){
  24. clearInterval(timer);
  25. return;
  26. }
  27. try{
  28. if(w<=screen.width+8)w+=2;
  29. if(h<=screen.height+8)h+=2;
  30. n.resizeTo(w,h)
  31. x=(screen.width-w)/2;
  32. y=(screen.height-h)/2;
  33. n.moveTo(x,y)
  34. }catch(e){}//shawl.qiuscript
  35. }
  36. //]]>
  37. </script>

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

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

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

    linenum
  1. <scripttype="text/javascript">
  2. //<![CDATA[
  3. functionscb()
  4. document.onmousedown=function()catch(e){}}
  5. document.ondblclick=function()
  6. //]]>//shawl.qiuscript
  7. </script>

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

分享到:
评论

相关推荐

Global site tag (gtag.js) - Google Analytics