js代码疑惑

来源:百度知道 编辑:UC知道 时间:2024/05/04 15:12:14
从书上看到有这样一堆代码,作用于实现浮动广告特效(就是那种有点弹动的感觉),看了以后功能虽实现了,但是里面的代码还有点不懂
show=function (id){
var _top = document.getElementById(id).offsetTop; /*获取该图片的上边距*/
var _left = document.getElementById(id).offsetLeft; /*获取该图片的左边距*/
var me=id.charAt?document.getElementById(id):id, d1=document.body, d2=document.documentElement;
d1.style.height=d2.style.height='100%';me.style.top=_top?_top+'px':0;me.style[(_left>0?'left':'right')]=_left?Math.abs(_left)+'px':0;
me.style.position='absolute';

setInterval(function (){
me.style.top=parseInt(me.style.top)+(Math.max(d1.scrollTop,d2.scrollTop)+_top-parseInt(me.style.top))*0.1+'px';},10+parseInt(Math.random()*20));
return arguments.callee;
};

window.onload=function (){
show
('lefttop')
('right')
}
这个就是它的中心代码,其中参数ID是指图片id,如(<img src

主要就这个啊 setInterval(function (){
me.style.top=parseInt(me.style.top)+(Math.max(d1.scrollTop,d2.scrollTop)+_top-parseInt(me.style.top))*0.1+'px';},10+parseInt(Math.random()*20));
return arguments.callee;
};
定时随机值 控制图片的css啊