asfman
android developer
posts - 90,  comments - 213,  trackbacks - 0
<script type="text/javascript">
<!--
    function ease(obj, prop){
    var start = parseInt(obj.style[prop]), end, round;
    setInterval(run, 1);
    function run(){
       end = document.documentElement.scrollTop + start;
       if(obj.offset != end){
       round = end - obj.offsetTop > 0 ? Math.ceil : Math.floor;
       obj.style[prop] = obj.offsetTop + round(end - obj.offsetTop)/10;
    }  
    }   
 }
 ease(document.getElementById("test"), "top");
//-->
</script>
posted on 2008-09-26 17:29 汪杰 阅读(207) 评论(1)  编辑 收藏 引用 所属分类: javascript

FeedBack:
# re: stay on the same position
2008-10-06 16:09 | 汪杰
/*
* FileName:
* Author: Asfman
* Date:
* Contact: http://jsframework.cn
* parameter:
* Need js:
*/
function StayPosition(speed)
{
this.objs = [];
this.speed = speed || 0.1;
this.timer = this.round = this.obj = this.end = null;
if(StayPosition.initialize !== true){
function correct(func, obj){
return function(){
func.call(obj);
}
}
StayPosition.prototype.start = function(){
this.timer = setInterval(correct(this.run, this), 33);
}
StayPosition.prototype.stop = function(){
clearInterval(this.timer);
}
StayPosition.prototype.capitalize = function(prop){return prop.replace(/^[a-z]/, function(a){return a.toUpperCase();})}
StayPosition.prototype.add = function(dom, prop){
var offset = prop ? "offset" + this.capitalize(prop) : "offsetTop";
var scroll = prop ? "scroll" + this.capitalize(prop) : "scrollTop";
prop = prop ? prop : this.offset.slice(6).toLowerCase();
this.objs.push({"dom": dom, "prop": {"size": dom[offset], "name": prop, "offset": offset, "scroll": scroll}});
}
StayPosition.prototype.run = function(){
for(var i = 0, l = this.objs.length; i < l; i++){
this.obj = this.objs[i];
this.end = (document.documentElement[this.obj.prop.scroll] || document.body[this.obj.prop.scroll]) + this.obj.prop.size;
if(this.end != this.obj.dom[this.obj.prop.offset]){
this.round = this.end - this.obj.dom[this.obj.prop.offset] > 0 ? Math.ceil : Math.floor;
this.obj.dom.style[this.obj.prop.name] = this.obj.dom[this.obj.prop.offset] + this.round((this.end - this.obj.dom[this.obj.prop.offset]) * this.speed) + "px";
}
}
}
}
StayPosition.initialize = true;
}  回复  更多评论
  
只有注册用户登录后才能发表评论。

<2024年4月>
31123456
78910111213
14151617181920
21222324252627
2829301234
567891011

常用链接

留言簿(15)

随笔分类(1)

随笔档案(90)

文章分类(727)

文章档案(712)

相册

收藏夹

http://blog.csdn.net/prodigynonsense

友情链接

最新随笔

搜索

  •  

积分与排名

  • 积分 - 457546
  • 排名 - 6

最新随笔

最新评论

阅读排行榜

评论排行榜