Move browser back slowly from this script
I have this script:
<script language="JavaScript1.2">
<!--
// Seismic window by Paul Anderson, copyright 1999 CNET, Inc.
var quakeID=0;
var deltaX=0;
var deltaY=0;
function tremor(dir) { // -10 to 10
with(Math) return ceil(random()*10)*2*(floor(random()*2)-.5);
}
function winQuake() {
clearTimeout(quakeID);
for (i=0;i<=((Math.random()*35)+5);i++) {
xShift = tremor();
yShift = tremor();
window.moveBy(xShift,yShift);
deltaX -= xShift;
deltaY -= yShift;
}
}
</script>
After about .5 seconds, I want the browsers window to gradually go back to its original place (0,0), adn finally being back to normal in about 2 seconds. How can I do this?
Moderate at JavaScriptCity Forums
John Pollock posted this at 19:52 — 1st June 2000.
He has: 628 posts
Joined: Mar 1999
This is *close* to what you want, I didn't have enough time left to try to make it retrace its steps (might not be too hard) but this will take the window over to (50,50) after the quake bit, and then scroll to (0,0).
Add these functions inside the script tags:
function goback()
{
dx=50;
dy=50;
window.moveTo(dx,dy);
setTimeout('goback2('+dx+','+dy+')',500);
}
function goback2(dx2,dy2)
{
var delay=50;
if((dx2 != 0) && (dy2 != 0))
{
window.moveBy(-1,-1);
dx2-=1;
dy2-=1;
}
setTimeout('goback2('+dx2+','+dy2+')',delay);
}
And at the end of the winQuake function where it has:
deltaX -= xShift;
deltaY -= yShift;
}
}
change it to:
deltaX -= xShift;
deltaY -= yShift;
}
goback();
}
Be careful if you change any numbers etc. because it can cause infinite loops. (I did it while testing).
Java Script: A Beginner's Guide
Page Resource
Arielladog posted this at 20:39 — 1st June 2000.
They have: 122 posts
Joined: Jun 1999
thank you, John. I guess that's what I needed. I just had to laugh about you playing around with the numbers...LOL. It is for an effect I am doing with a webpage for flash when a huge object comes in and "lands" on the screen. I didn't want the screen to stay that way forever..hehe. Thanx a lot. It is greatly appreciated
Moderate at JavaScriptCity Forums
Want to join the discussion? Create an account or log in if you already have one. Joining is fast, free and painless! We’ll even whisk you back here when you’ve finished.