您的位置:首页 > 编程语言

解决IE6中固定定位问题(代码)

2013-10-07 13:31 302 查看
/*

传对象进来,第二个参数为距离底边的距离,可以不传,new一个出去执行this.move()就可以了

比如 window.onscroll = function(){ a.move()}

@param obj 对象必须传递

@param bottom 选择传递 对象距离浏览器下方的距离

/

function rightSusBox(obj,bottom){

var timer = null;

this.bottom = 0;

if(arguments.length==2){

this.bottom = bottom;

}

this.move = function(){

var scrollTop = document.documentElement.scrollTop||document.body.scrollTop;

var iTarget = scrollTop + document.documentElement.clientHeight - this.bottom - obj.offsetHeight;

clearInterval(timer);

timer = setInterval(function(){

var speed = (iTarget - obj.offsetTop)/6;

speed = speed>0?Math.ceil(speed):Math.floor(speed);

if(iTarget==obj.offsetTop){

clearInterval(timer);

}else{

obj.style.top = obj.offsetTop + speed + 'px';

}

},30);

};

this.move();

}

在移动过程中,对象会呈现缓冲运动效果
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: