Copy Code code as follows:
/*
* Copyright (C) 2007-2009 Skylark
* email:aohailin@gmail.com
* version:2.1
* Original procedures, reproduced please retain the copyright
*/
var $=function (o) {return typeof o== "string"? document.getElementById (o):;
function AutoScroll () {
This.obj=[];
this.version= "2.1";
This. Build ();//Initialize
};
Autoscroll.prototype.build=function () {
var me=this;
Get other scrolling events
var Oldscroll=window.onscroll;
Window.onscroll=function () {
Protect other scrolling events
if ("function" ==typeof oldscroll) {
Oldscroll ();
}
Get the client browser parameters, compatible Ie,ff,chrome
this.common={
t:document.documentelement.scrolltop| | Document.body.scrollTop,
h:document.documentelement.clientheight| | Document.body.clientHeight,
w:document.documentelement.clientwidth| | Document.body.clientWidth
};
This.position=[];
for (Var i=0;i<me.obj.length;i++) {
try{
this.style={};
Get the client location, set up 7 different locations
In order to minimize the automatic adaptation of position, where the dynamic calculation of position, so scrolling event triggered, CPU consumption is very large
this.position[i]=[
{x:0,y:this.common.t},
{x:this.common.w-me.obj[i].obj.offsetwidth,y:this.common.t},
{x:0,y: (this.common.h+this.common.t-me.obj[i].obj.offsetheight)/2+ (THIS.COMMON.T)/2},
{x:this.common.w-me.obj[i].obj.offsetwidth,y: (this.common.h+this.common.t-me.obj[i].obj.offsetheight)/2+ ( THIS.COMMON.T)/2},
{x: (this.common.w-me.obj[i].obj.offsetwidth)/2,y: (this.common.h+this.common.t-me.obj[i].obj.offsetheight)/2+ ( THIS.COMMON.T)/2},
{X:0,y:this.common.h+this.common.t-me.obj[i].obj.offsetheight},
{X:this.common.w-me.obj[i].obj.offsetwidth,y:this.common.h+this.common.t-me.obj[i].obj.offsetheight}
];
Working with custom styles
This.style= "Object" ==typeof Me.obj[i].style? {x:me.obj[i].style.left,y:me.obj[i].style.top+this.common.t}:{x:this.position[i][me.obj[i].style].x,y: THIS.POSITION[I][ME.OBJ[I].STYLE].Y};
Positioning
me.obj[i].obj.style.left=this.style.x+ "px";
me.obj[i].obj.style.top=this.style.y+ "px";
}catch (e) {
function is to filter invalid obj
for (Var j=i;j<me.obj.length-1;j++) {
ME.OBJ[J]=ME.OBJ[J+1];
Me.obj.length=me.obj.length-1;
}
}
}
};
Class
Window.Scroll (1,1);
};
Autoscroll.prototype.add=function () {
var obj=arguments[0];
Get Current position
var oldposition=$ (obj.id). Style.position;
$ (obj.id). style.position= "Absolute";
Do not use fixed, although newer browsers have supported fixed
This.obj.push ({
obj:$ (obj.id),
Oldposition:oldposition,
Style:obj.style
});
};
Autoscroll.prototype.remove=function () {
var obj=arguments[0];
for (Var i=0;i<this.obj.length;i++) {
if (this.obj[i].obj==$ (obj.id)) {
Restore Initial state position
This.obj[i].obj.style.position=this.obj[i].oldposition;
Whether to really remove
if (obj.remove) {
This.obj[i].obj.innerhtml= "";
Document.body.removeChild (This.obj[i].obj);
}
Remove obj
for (Var j=i;j<this.obj.length-1;j++) {
THIS.OBJ[J]=THIS.OBJ[J+1];
}
This.obj.length=this.obj.length-1;
Break
}
}
};
var scroller=new autoscroll ();