myQuery 物件導向設計

2022-03-04 22:42:47 字數 2703 閱讀 1990

最近考慮對於自己的query進行物件導向的寫法,參考了很多**,也想了很多,當然這物件導向寫著十分噁心,所以更新速度會慢,先mark下

才發現更新的好慢啊,沒事,慢慢來嘛!

新增第乙個物件導向寫的玩意

js拖動介面元素--首先你需要對要拖動的那個元素設position:absolute

1

function

drag(id)15}

16 drag.prototype=

28 document.onmouseup=function

()31

},32 startmove:function

(event),

39 endmove:function

(),43 limite:function

()46 }

view code

js拖動介面元素2--附加方法

1

function

drag(id,options)

1718

}19 drag.prototype=;

30//

遍歷json然後返回出去

31for ( var i in options ) this.options[i] =options[i]

32},

33 startdrag: function

( event )

38this.handler.innerhtml='oh yeah';

39this.css(this.handler,);

40var _this = this;41

var event = event ||window.event;

42this.disx = event.clientx - this

.drag.offsetleft;

43this.disy = event.clienty - this

.drag.offsettop;

44 document.onmousemove=function

()47 document.onmouseup=function

()50

},51 startmove: function

( event)

60if ( this

.limit )

64else

if ( l > document.documentelement.clientwidth - this

.drag.offsetwidth )

67if ( t < 0)

70else

if ( t > document.documentelement.clientheight - this

.drag.offsetheight ) 73}

74this.drag.value='yeah';

75this.lockx || (this.drag.style.left = l + 'px');

76this.locky || (this.drag.style.top = t + 'px');

77},

78 endmove: function

() );

81this.handler.innerhtml='drag me';

82},

83//

新增事件繫結

84 addhandler: function

( obj, type, handler ) else

if( obj.attachevent ) else

92},

93//

刪除繫結事件

94 removehandler: function

( oelement, seventtype, fnhandler ) ,

97//

繫結事件到物件

98 bind: function

( object, fnhandler )

102},

103 css: function

(obj,json)

107}

108 }

view code

幫群裡解決了關於這個的問題,順便封裝到了jquery下

1

$.fn.extend()

7this.mousedown(function

(ev));

12});

13 $(document).mouseup(function

());

16return

false;17

})18

}19 })

view code

自定義alert和confirem--不完善版本,偷懶,所以需要引入jquery

1

2353

5455

顯示alert浮層

56顯示confirm浮層

5758

5960159

view code

物件導向設計

物件導向設計 object oriented design,ood 方法是oo方法中乙個中間過渡環節。其主要作用是對ooa分析的結果作進一步的規範化整理,以便能夠被oop直接接受。物件導向設計 ood 是一種軟體設計方法,是一種工程化規範。這是毫無疑問的。按照bjarne stroustrup的說法...

物件導向設計

1 物件導向的三要素 1.1 封裝 encapsulation a 封裝 合理的隱藏資料的隱藏 隱藏在方法背後 實現的隱藏 隱藏在介面背後 變化的隱藏 隱藏在抽象背後 b 封裝能夠提高物件的復用性 減低物件的耦合度c 良好的封裝 物件的高內聚 1.2 繼承 inheritance a 基於差異式程式...

物件導向設計

物件導向的設計把握乙個重要原則 誰擁有資料,誰就對外提供操作這些資料的方法。人在黑板上畫圓 person,blackboard,circle draw 列車司機在剎車 人關門 兩塊石頭磨成一把石刀,石刀可以砍樹,砍成木材,木材可以做椅子。stone石頭 stoneknife石刀 stoneknife...