📄 windowjump_source.html
字号:
<HEAD><TITLE>Source for Moving Browser</TITLE><LINK rel=stylesheet type=text/css HREF=../../style/jsdemo.css></HEAD><BODY BGCOLOR=#CCCCCC MARGINHEIGHT=0 MARGINWIDTH=0 TOPMARGIN=0 LEFTMARGIN=0><TABLE bgColor=#8899aa border=0 cellPadding=4 cellSpacing=0 width=100%> <TR> <TD class=title>  NetProg 2002: Source for Moving Browser </TD> </TR> <TR bgColor=black height=10><TD CLASS=menu> </TD></TR></TABLE><DIV CLASS=page><BR><BR><P><CENTER><TABLE BORDER=0 BGCOLOR=#8899aa CELLPADDING=5><TR><TD><TABLE bgcolor=white BORDER=0 CELLPADDING=10><TR><TD><PRE class=codebox><HEAD>
<TITLE>Netprog JavaScript Demo - Moving Browser</TITLE>
<SCRIPT LANGUAGE=JavaScript><SPAN CLASS=code>
<!--
// move moves the position of the window
// it's current location.
// positive xinc will move to the right (neg to the left)
// positive yinc will move down (neg up)
function move( xinc, yinc ) {
var jsize=20;
window.moveBy(jsize*xinc,jsize*yinc);
}
// random jump to anywhere
function hjump() {
xpos = Math.random() * 600
ypos = Math.random() * 400
window.moveTo(xpos,ypos);
}
// variable used to keep track of when the game is running
var running=0;
// start up the game
function hyperspace_game() {
running=1;
hyperspace_move();
}
// stop the game
function stop_hyperspace_game() {
running=0;
}
// make a single game move by moving the image to a random
// location and then setting up to call this routine again
// after some delay. The delay before the next call is
// based on the value of the speed field (the user can change).
function hyperspace_move() {
var delay = document.frm.speed.value;
if (delay < 500) {
document.frm.speed.value = 500;
}
if (running == 1) {
hjump();
setTimeout("hyperspace_move()",delay);
}
}
// -->
</SPAN></SCRIPT>
</HEAD>
<BODY BGCOLOR=WHITE onUnload="<SPAN CLASS=code>restore()</SPAN>">
<TABLE HEIGHT=380 WIDTH=200 BORDER=2>
<TD BGCOLOR=CYAN>
<FORM Name=frm>
<CENTER>Move the browser</CENTER><BR>
<TABLE>
<TR ALIGN=CENTER>
<TD> </TD>
<TD><INPUT TYPE=BUTTON Name=up WIDTH=50 Value="Up" onClick="<SPAN CLASS=code>move(0,-1)</SPAN>"></TD>
<TD> </TD>
</TR>
<TR>
<TD><INPUT TYPE=BUTTON WIDTH=50 Name=left Value="Left" onClick="<SPAN CLASS=code>move(-1,0)</SPAN>"></TD>
<TD> </TD>
<TD><INPUT TYPE=BUTTON WIDTH=50 Name=right Value="Right" onClick="<SPAN CLASS=code>move(1,0)</SPAN>"></TD>
</TR>
<TR>
<TD> </TD>
<TD><INPUT TYPE=BUTTON WIDTH=50 Name=down Value="Down" onClick="<SPAN CLASS=code>move(0,1)</SPAN>"></TD>
<TD> </TD>
</TR>
</TABLE>
<P>
<CENTER>
<INPUT TYPE=BUTTON Name=jump Value="Random Jump" onClick="<SPAN CLASS=code>hjump()</SPAN>">
</CENTER>
<HR>
<CENTER>Play the chase game</CENTER><BR>
<CENTER>
<INPUT TYPE=BUTTON WIDTH=70 Name=chase Value="Start" onClick="<SPAN CLASS=code>hyperspace_game()</SPAN>">
<INPUT TYPE=BUTTON WIDTH=70 Name=chase Value="Stop" onClick="<SPAN CLASS=code>stop_hyperspace_game()</SPAN>">
</CENTER>
<BR>
Speed : <INPUT TYPE=TEXT SIZE=5 Name=speed><BR>
<HR>
</FORM>
</TD>
</TR></TABLE>
<SCRIPT><SPAN CLASS=code>
// save the initial window size (so we can restore it)
savewidth = window.innerWidth;
saveheight = window.innerHeight;
function restore() {
// Change the window size to the original values
window.innerWidth=savewidth;
window.innerHeight=saveheight;
}
// Change the window size to hold the controls only
//window.innerWidth=220;
//window.innerHeight=400;
window.resizeTo(300,600);
// initialize the game speed field to 2000
document.frm.speed.value=2000;
</SPAN></SCRIPT>
</BODY></PRE></TD></TR></TABLE></TD></TR></TABLE></CENTER></DIV>
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -