实现弹出广告框几秒钟自动消失

来源:互联网 发布:win7分辨率修改软件 编辑:程序博客网 时间:2024/04/28 10:47
<SCRIPT>
<!--


var flyingwin
var popupwidth=200  //弹出窗口宽度
var popupheight=150  //弹出窗口高度
var marginright
var windowcenter
var I_top=200
var I_left=-popupwidth-50
var step=40
var timer
var waitingtime=3000 //时间为三秒(以毫秒为单位)
var pause=20


function showWindow() {
flyingwin = window.open("", "flyingwin", "toolbar=no,width="+popupwidth+",height="+popupheight+",top=100,left="+(-popupwidth)+"");
flyingwin.document.open();
flyingwin.document.write("<html><title>漂浮的窗口</title><body><p align=center>我来了!不过一会就走!</body></html>");
flyingwin.document.close();

if (document.all) {
marginright = screen.width+50
}
if (document.layers) {
marginright = screen.width+50
}
windowcenter=Math.floor(marginright/2)-Math.floor(popupwidth/2)
movewindow()

}


function movewindow() {
if (I_left<=windowcenter) {
flyingwin.moveTo(I_left,I_top)
I_left+=step
timer= setTimeout("movewindow()",pause)
}
else {
clearTimeout(timer)
timer= setTimeout("movewindow2()",waitingtime)
}
}


function movewindow2() {
if (I_left<=marginright) {
flyingwin.moveTo(I_left,I_top)
I_left+=step
timer= setTimeout("movewindow2()",pause)
}
else {
clearTimeout(timer)
flyingwin.close()
}
}


// -->
</SCRIPT>
<body onload=showWindow() >