/*
* Copyright (C) 2007-2009 skylark
* Email:aohailin@gmail.com
* Version:2.1
* Original program, please retain copyright for reprinting
*/
var $=function(o){return typeof o==" string"?document.getElementById(o):o;};
function AutoScroll(){
this.obj=[];
this.version="2.1";
this.Build( );//Initialization
};
AutoScroll.prototype.Build=function(){
var me=this;
//Get other scroll events
var oldscroll=window.onscroll;
window.onscroll=function(){
//Protect other scroll events
if("function"==typeof oldscroll){
oldscroll();
}
// Get client browser parameters, compatible with 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 and set 7 positions
//In order to minimize the automatic Adapt to the position. The position is dynamically calculated here, so when the scroll event is triggered, the 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}
];
//Handling 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};
//Position
me.obj[i].obj.style.left=this.style.x "px";
me.obj[i].obj.style.top=this.style.y "px";
}catch(e){
//The function is to filter invalid obj
for(var j=i;jme.obj[j] =me.obj[j 1];
me.obj.length=me.obj.length-1;
}
}
}
};
//Initialization
window.scroll(1,1);
};
AutoScroll.prototype.Add=function(){
var obj=arguments[0];
//Get the current position
var oldposition=$(obj.id).style.position;
$(obj.id).style.position="absolute";
//Do not use fixed, although higher version browsers already support it fixed
this.obj.push({
obj:$(obj.id),
oldposition:oldposition,
style:obj.style
});
};
AutoScroll.prototype.Remove=function(){
var obj=arguments[0];
for(var i=0;iif(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;jthis.obj[j] =this.obj[j 1];
}
this.obj.length=this.obj.length-1;
break;
}
}
};
var Scroller=new AutoScroll();
Statement:The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn