//id:string是要控制的目标,nheight:number是其高度,toBottom:number到底部的距离
//topLeft:number是到浏览器边缘的距离,which:string是决定向左还是向右
//可以实现对多个目标的控制
//example:new fixed('hehe',20,300,20,'right');
function fixed(id,nheight,toBottom,toLeft,whitch)
{
this.bottomInfo=document.getElementById(id);
this.bottomInfo.style.position='absolute';
this.bottomInfo.style.display='block';
//this.height;
var now=this;
function getIt(){
return(document.documentElement.clientHeight+document.documentElement.scrollTop-toBottom);
}
function addEventSimple(obj,evt,fn){
if(obj.addEventListener){
obj.addEventListener(evt,fn,false);}else if(obj.attachEvent){
obj.attachEvent('on'+evt,fn);
}
}
if(whitch=="right"){
this.bottomInfo.style.right=toLeft+"px";
} else if(whitch=="left"){
this.bottomInfo.style.left=toLeft+"px";
};
this.bottomInfo.style.top= getIt()+"px";//here we don't support %;
this.timer;
addEventSimple(window,'scroll',function() {
clearTimeout(now.timer);//here setTimeout is not neceesary,can be leave out; now.timer = setTimeout(function() { now.bottomInfo.style.top= getIt()+"px"; }, 50); });
addEventSimple(window,'resize',function(){ now.bottomInfo.style.top=getIt()+"px"; });
}