用的prototype
1var DivMove = Class.create();
2DivMove.prototype = {
3 initialize : function(){},
4 init : function(element) {
5 this._element = element;
6 },
7 observer : function() {
8 Event.observe(this._element, 'mousedown', this._mouseDown);
9 Event.observe(this._element, 'mouseup', this._mouseUp);
10 },
11 _mouseDown : function(e) {
12 var event = e || window.event;
13 var offsetX = event.clientX - this.offsetLeft;
14 var offsetY = event.clientY - this.offsetTop;
15 Event.observe(this, 'mousemove', function(e) {
16 var event = e || window.event;
17 var st = Math.max(document.body.scrollTop,
18 document.documentElement.scrollTop);
19 var sl = Math.max(document.body.scrollLeft,
20 document.documentElement.scrollLeft);
21
22 Element.setStyle(this ,{
23 left : event.clientX + sl - offsetX+'px',
24 top : event.clientY + st - offsetY+'px',
25 position : 'absolute'
26 });
27 /**//*
28 * this.style.position = 'absolute'; this.style.left = event.clientX +
29 * sl - offsetX; this.style.top = event.clientY + st - offsetY;
30 */
31 });
32
33 },
34 _mouseUp : function(e) {
35 Event.stopObserving(this,'mousemove',this.onMousemove);
36 }
37};
38var move=new DivMove();
39move.init($('selectItem'));
40move.observer();
41
42var move2=new DivMove();
43move2.init($('selectItem1'));
44move2.observer();
posted on 2010-02-04 11:15
岩石 阅读(126)
评论(0) 编辑 收藏