列表滚动方法

2018-07-06  本文已影响0人  shougg22
            //isDetail 参数是为了解决增加点击按钮滚动时的一个标识符 , 如果是单纯的列表滚动,可不用传此参数
            var canMoveDetailBox=true;

            function doMove(obj, attr, iTarget,isDetail) {
                clearInterval(obj.timer);
                obj.timer = setInterval(function() {
                    var iCur = 0;
                    if (attr == 'opacity') {
                        iCur = parseInt(parseFloat(getStyle(obj, attr)) * 100);
                    } else {
                        iCur = parseInt(getStyle(obj, attr));
                    }
                    var iSpeed = (iTarget - iCur) / 8;
                    iSpeed = iSpeed > 0 ? Math.ceil(iSpeed) : Math.floor(iSpeed);
                    if (iCur == iTarget) {
                        clearInterval(obj.timer);
                        if(isDetail){
                            canMoveDetailBox=true;
                        }
                        
                    } else {
                        if (attr == 'opacity') {
                            obj.style.filter = 'alpha(opacity:' + (iCur + iSpeed) + ')';
                            obj.style.opacity = (iCur + iSpeed) / 100;
                        } else {
                            obj.style[attr] = iCur + iSpeed + 'px';
                        }
                        canMoveDetailBox=false;
                    }
                }, 30)
            };
            function getStyle(obj, attr) {
                if (obj.currentStyle) {
                    return obj.currentStyle[attr];
                } else {
                    return getComputedStyle(obj, false)[attr];
                }
            };
上一篇下一篇

猜你喜欢

热点阅读