随笔 - 11  文章 - 3  trackbacks - 0
<2010年1月>
272829303112
3456789
10111213141516
17181920212223
24252627282930
31123456

常用链接

留言簿

随笔档案

文章档案

搜索

  •  

最新评论

阅读排行榜

评论排行榜

主要功能:
1.拖动
2.可配置相对位置
3.平滑移动

CE.Tween = {
 plcMove : function(o, a, s, e, callback, speed){
  var sTime = +new Date(), p, speed = speed || 100;
  var iTimer = setInterval(function(){
   p = (+new Date() - sTime) / speed;
   if(p >= 1){
    o.style[a] = e + "px";
    callback && callback.call(o);
    o = null;
    return clearInterval(iTimer);
   }
   o.style[a] = s + (e - s) * ((-Math.cos(p * Math.PI) / 2) + 0.5) + "px";
  }, 10);
 }
};

CE.Util.Drag 
= {
    dcount : 
0,
    dList : {},
    bind : function(c,obj){
        var _this 
= CE.Util.Drag;

        var _d 
= obj.d || c;

        
if(!_d){return;}

        
if(!_d.did){

            _d.did 
= _this.dcount++;

            _this.dList[_d.did] 
= _d;

            var _x ,_y,_isdown 
= false,_scape = null,_p = null;

            _d.style.cursor 
= "move";

            var down 
= function(e){
                _isdown 
= true;

                _p 
= obj.refer || document.body;

                _x 
= e.clientX - _d.offsetLeft; //初始坐标
                _y = e.clientY - _d.offsetTop;

                
if(null == _scape){
                    _scape 
= document.createElement("div");
                    _p.appendChild(_scape);
                }

                _scape.style.border 
= "1px dotted #06459c";
                _scape.style.position 
= "absolute";
                _scape.style.zIndex 
= c.style.zIndex + 1 || 1;
                _scape.style.width 
= c.style.width;
                _scape.style.height 
= c.style.height;
                _scape.style.left 
= c.offsetLeft + "px";
                _scape.style.top 
= c.offsetTop + "px";

                c.style.filter 
= "Alpha(Opacity=60)";
                c.style.opacity 
= 0.6;

                
if(_scape){
                    CE.Event.addListener(document,
"mousemove",move);
                    CE.Event.addListener(document,
"mouseup",up);
                    document.onselectstart 
= function() {return false};
                    
if(window.getSelection){ //非ie
                        window.getSelection().removeAllRanges();
                    }
                }
            };
            var move 
= function(e){
                
if(!_isdown){return};
                _scape.style.left 
= e.clientX - _x + "px";
                _scape.style.top 
= e.clientY - _y + "px";
            };
            var up 
= function(){
                _isdown 
= false;
                
if(_scape){
                    
if(obj.tween){
                        CE.Tween.plcMove(c,
"top",parseInt(c.style.top, 10),_scape.offsetTop);
                        CE.Tween.plcMove(c,
"left",parseInt(c.style.left, 10),_scape.offsetLeft);
                    }
else{
                        c.style.left 
= _scape.offsetLeft + "px";
                        c.style.top 
= _scape.offsetTop + "px";
                    }
                    c.style.filter 
= "Alpha(Opacity=100)";
                    c.style.opacity 
= 1;
                    _scape.style.zIndex 
= c.zIndex - 1 || -1;
                    _p.removeChild(_scape);
                    _p 
= null;
                    _scape 
= null;
                    document.onselectstart 
= function() {return true};
                }
            };
            CE.Event.addListener(_d,
"mousedown",down);
        }
else{
            
for(var item in _this.dList){
                
if(_d.did === item.did){
                    
return;
                }
            }
        }
    }
};
posted on 2010-01-17 12:16 jacklau 阅读(173) 评论(0)  编辑  收藏

只有注册用户登录后才能发表评论。


网站导航: