PDA

View Full Version : "jQuery Scroll to Top Control v1.1" - Number of pixels from the bottom of the page



topdog
07-23-2014, 02:41 AM
1) Script Title: jQuery Scroll to Top Control v1.1

2) Script URL (on DD): http://www.dynamicdrive.com/dynamicindex3/scrolltop.htm

3) Describe problem: I have this page on my website, which I update it regularly, so the page length changes in time (goes up and down).

The jQuery says: the number of pixels the user's scrollbar should be from the top of the page before revealing the control.

How can I make it from the bottom of the page?

Thank you.

vwphillips
07-24-2014, 10:47 AM
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
"http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">

<html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en" lang="en">

<head>
<title></title>
<style type="text/css">
/*<![CDATA[*/
#scrolltop {
position:fixed;z-Index:101;bottom:5px;right:5px;width:100px;
}


/*]]>*/
</style></head>

<body>
<div style="height:2000px;" ></div>
<img id="scrolltop" src="http://www.vicsjavascripts.org/StdImages/1.gif" />

<script type="text/javascript">
/*<![CDATA[*/

function zxcScrollTop(o){
var t=document.getElementById(o.MarkID),y=o.Bottom,ms=o.Animate,b=document.createElement('DIV');
if (t&&typeof(y)=='number'&&y>0){
b.style.width=b.style.height='0px';
document.body.appendChild(t);
document.body.appendChild(b);
this.t=t;
this.y=y;
this.b=b;
this.ms=typeof(ms)=='number'&&ms>0?ms:1000;
this.addevt(t,'click','top');
this.addevt(window,'scroll','scroll');
this.s=[0,0];
this.f=[t,0];
this.scroll();
}
}

zxcScrollTop.prototype={

scroll:function(){
var s=window.innerHeight?window.pageYOffset:document.documentElement.clientHeight?document.documentElement.scrollTop:document.body.scrollTop;
var g=s<this.b.offsetTop-this.y;
if (this.g!=g){
this.t.style.visibility='visible';
this.animate(this.f,this.f[1],g?0:100,new Date(),this.ms);
}
this.s[1]=s;
this.g=g;
},

top:function(){
this.animate(this.s,this.s[1],0,new Date(),this.ms);
},


animate:function(a,f,t,srt,mS){
clearTimeout(a[4]);
var oop=this,ms=new Date()-srt,n=(t-f)/mS*ms+f;
if (isFinite(n)){
a[1]=n;
a==oop.s?window.scrollTo(0,n):oop.opc(a[0],n);
}
if (ms<mS){
a[4]=setTimeout(function(){ oop.animate(a,f,t,srt,mS); },10);
}
else {
a[1]=t;
a==oop.f&&t==0?a[0].style.visibility='hidden':null;
}
},

opc:function(o,n){
o.style.filter='alpha(opacity='+n+')';
o.style.opacity=o.style.MozOpacity=o.style.WebkitOpacity=o.style.KhtmlOpacity=n/100-.001;
},

addevt:function(o,t,f,p,p1){
var oop=this;
o.addEventListener?o.addEventListener(t,function(e){ return oop[f](p,p1);},false):o.attachEvent?o.attachEvent('on'+t,function(e){ return oop[f](p,p1); }):null;
}


}

new zxcScrollTop({
MarkID:'scrolltop',
Bottom:1000,
Animate:1000
})
/*]]>*/
</script>

</body>

</html>