作者Qiu0 (有時會倔強過了頭...)
看板Ajax
標題[問題] 如何傳值
時間Tue Sep 6 17:45:47 2011
想請教各位前輩~
我有一個class 叫 CarouselItem
在這裡頭我想要加入圖片的Width and Height Data
所以我用
_image.onload的方式去取得圖片尺寸
但是想很久就是不曉得該怎麼把值給傳出來
想請大家給我意見<(_ _)> 程式碼如下,謝謝
function CarouselItem(Parent, HREF, ImageSRC, ImageAlt) {
this._parent = Parent;
this._ID = this._parent._ID + 'Item' + this._parent._items.length;
this._href = HREF;
this._element = null;
this._position = new Vector2D(0, 0);
this._size = this._parent._itemSize.Clone();
this._image = new Image();
this._imageH = 0;
this._imageW = 0;
this._image.onload = function () {
this._imageW = this.width; //這是錯的 i konw> <
this._imageH = this.height;
}
。
。
。
--
※ 發信站: 批踢踢實業坊(ptt.cc)
◆ From: 210.63.100.2
※ 編輯: Qiu0 來自: 210.63.100.2 (09/06 17:47)
1F:→ bibo9901:this._imageW和this.width的this是不一樣的 09/06 18:45
2F:→ Qiu0:I know>< 所以才苦惱不曉得怎麼取出來餵給this._imageW 09/07 11:02
3F:→ sk1765:在this._image.onload = function () {這行上面寫 09/07 11:11
4F:→ sk1765:var that = this ; 在this._image.onload = function () { 09/07 11:11
5F:→ sk1765:這行下面用that._imageW = this.width; 09/07 11:12
6F:→ sk1765:或多一個參數x this._image.onload = function (x) { 09/07 11:13
7F:→ sk1765:不行不能用參數傳 09/07 11:20