作者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