Create and Move PopUp

[Total: 0    Average: 0/5]

This file shows how to create a popup window and move it around the window.

Head Code:

<script type="text/javascript">
var x=0,y=0,w=200,h=100, dx=5,dy=5, interval=100
var win=null;
var intervalID;
function startIt() {
  win=window.open('javascript:"<H1>My Moving Window</H1>"',"","width="+w+",height="+h)
  win.moveTo(x,y)
  intervalID = window.setInterval("bounce()",interval)
}
var running=false;
var close=false;
function bounce() {
  running=true
  if (win.closed) {
    clearInterval(intervalID)
	running=false
    return
  }
  if ((x+dx>(500-w)) || (x+dx<0))dx=-dx
  if ((y+dy>(500-h)) || (y+dy<0))dx=-dy
  x+=dx
  y+=dy
  win.moveTo(x,y)
  if (close) {
    win.close()
	clearInterval(intervalID)
  }
}
function closeWin() {
  if (running)
    close=true
}
</script>

Body Code:

<a href="#" onMouseOver='startIt()'>MOUSE OVER TO START</a><BR><BR>
<a href="#" onMouseOver='closeWin()'>MOUSE OVER TO CLOSE POPUP</a>

Times Viewed: 0

Leave a Reply

Your email address will not be published. Required fields are marked *