日期:2014-05-16  浏览次数:20370 次

自己做的一个跟随滚动的代码,求拍砖!
不知道有哪些需要改进的地方或者不兼容的地方

JScript code

<script type="text/javascript">
var $=function(ID){return document.getElementById(ID);};
var timer=null,speed=36,y=0.1;
window.onscroll=function(){
    if(timer) {
        clearTimeout(timer);
    }
    timer=null;
    ;(function(){
        st=document.body.scrollTop||document.documentElement.scrollTop;
        if(parseInt($("test").style.top)<st+120){
            $("test").style.top=parseInt($("test").style.top)+Math.ceil((st+120-parseInt($("test").style.top))*y)+"px";
        } else if(parseInt($("test").style.top)>st+120){
            $("test").style.top=parseInt($("test").style.top)-Math.ceil((parseInt($("test").style.top)-120-st)*y)+"px";
        } else {
            clearTimeout(timer);
            timer=null;
        }
        timer=setTimeout(arguments.callee,speed);
    })();
}
//page 287 event2
//page 312 oscroll
</script>






------解决方案--------------------
楼主先把html代码贴出来,至少看下效果吧
------解决方案--------------------
好像少了点啥
------解决方案--------------------
ff chorme ie9 都看了下。。还是可以的。。。
------解决方案--------------------
效果还不错就是就是效果写固定了,最好能提炼封装下,让别人用只需要设定参数不需要改动你的代码。