Scroll Up!
This page is complete; just save it and follow the instructions.
Features:
Microsoft's Internet Explorer cannot process this script properly without a vaild doctype.
For more information on doctypes go to www.w3.org/QA/2002/04/valid-dtd-list.html.
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8">
<title>Scroll to Top of Page</title>
<style type="text/css">
#up_ {
background-color: yellow;
position: fixed; /* fixes arrow in bottom, right corner of screen */
bottom: 25px;
right: 25px;
filter: alpha(opacity=0); /* for Internet Explorer */
opacity: 0.0; /* W3C standard */
cursor: pointer
}
</style>
<script type="text/javascript">
var Up=
{
distance:350, // scroll distance till 'scroll up' appears
appear:20, // speed opacity changes
time:20, // speed (lower number is faster)
frames:75,
stpUp:25, // adjusts acceleration
stpDwn:36.8, // adjusts deceleration
// don't touch from here down
upTimer:0,
opcty:0,
up1:0,
up2:0,
scroll_page: function(){
if (navigator.appName=='Microsoft Internet Explorer') IE=true
else IE=false
document.getElementById('up_').onclick=Up.scrollUp
Up.poll()
},
poll: function(){
if(IE==true){
if(document.documentElement.scrollTop>Up.distance) Up.fade(1)
else Up.fade(0)
}
else{
if(window.pageYOffset>Up.distance)Up.fade(1)
else Up.fade(0)
}
up_timer=setTimeout('Up.poll()',100)
},
fade: function(a){
if(a==1){
if(Up.opcty<.9){
Up.opcty+=.05
window.clearTimeout(Up.up2)
Up.up1=setTimeout('Up.fade(1)',25)}
else Up.opcty=1
}
else {
if(Up.opcty>.1){
Up.opcty-=.05
window.clearTimeout(Up.up1)
Up.up2=setTimeout('Up.fade(0)',25)}
else Up.opcty=0
}
if (IE==true) document.getElementById("up_").filters[0].opacity=Up.opcty*100
else document.getElementById("up_").style.opacity=Up.opcty
},
scrollUp: function(){
t_f=Up.time/Up.frames
if (IE==true)scrllP=document.documentElement.scrollTop
else scrllP=window.pageYOffset
step=scrllP/Up.frames
sU=step/Up.stpUp
sD=step/Up.stpDwn
move=3
window.clearTimeout(Up.upTimer)
Up.scroll_(step,scrllP,scrllP,sU,sD)
},
scroll_: function(stp,cP,sP,sU,sD){
prcnt=cP/sP
if(prcnt>=.25){
move+=sU
if(move>stp)move=stp}
if(prcnt<.25){move-=sD
if(move<2.5)move=2}
cP-=move
if (cP>0){
window.scrollTo(0,cP)
Up.upTimer=setTimeout('Up.scroll_('+stp+','+cP+','+sP+','+sU+','+sD+')',Up.time)}
else window.scrollTo(0,0)
cP=0; sU=0; sD=0; stp=0
}
}
</script>
</head>
<body onload="scroll_page()" >
<p id="up_">Scroll Up!</p>
Or, if you prefer an up arrow, you can make this a link to an image file.
<img id="up_" src="../images/up.GIF" alt="Scroll Up" >
I hope this script works to your satisfaction.
</body>
</html>