【发布时间】:2012-02-09 02:44:06
【问题描述】:
我有以下功能
"use strict";
function Player
{
this.width;
this.height;
this.framesA = 5;
this.image = new Image();
this.image.onload = function ()
{
width = this.width;
height = this.height / framesA;
}
this.image.src = "Images/angel.png";
}
如何使此代码正常工作?
我希望在调用 onload 函数时将 Player 函数中的宽度和高度与图像的宽度和高度结合起来。
我需要这个才能在严格模式下工作(必须)。
如果这应该以其他方式完成,请随时教。
编辑:我更新了代码以反映更现实的情况(我不知道这会这么复杂)
编辑 2: 代码的另一个更新。我没有注意到我写了 var insted 这个。对不起。
提前致谢
【问题讨论】:
-
只需使用
this.image.width和this.image.height... -
你的例子应该可以工作,我想,有什么问题?
-
@Šime Vidas 我需要保存该值,以便获得解决方案
标签: javascript image syntax onload strict