English 中文(简体)
Javascript Value.onload callsback to Object function
原标题:Javascript Image.onload callback to object function

这给我带来了营养——我一直在圈子里,这是不受欢迎的。 我装上了多种动态图像,并有一个简单的 Java字标语,我对每个图像都进行了即时检查,一旦图像装满同步,就会有倒退。

I have verified that the callback code works just fine on a stand-alone basis (ie. I can call the callback manually after the image has loaded, and the image is rendered correctly), and I have verified that the image itself is successfully loaded (by switching the object s callback for a simple one line logging function), but when I try to tie it all together, the callback apparently never gets invoked.

我对联合材料说得较新,我怀疑,我缺少一些关于目标内职能定义的基本内容,但尽管有很多戈格罗宁,我还是可以做些什么。

请有人告诉我我我我我,我的方法有误?

function ImageHolder(aX,aY,aW,aH, anImageURL) {
    this.posx=aX;
    this.posy=aY;
    this.posw=aW;
    this.posh=aH;
    this.url=anImageURL;

    this.myImage = new Image();
    this.myImage.onload=this.onload;
    this.myImage.src=anImageURL;
    this.onload=function() {

        try {
            var d=document.getElementById("d");
            var mycanvas=d.getContext( 2d );
            mycanvas.drawImage(this.myImage, this.posx, this.posy, this.posw, this.posh);
            } catch(err) {
                console.log( Onload: could not draw image  +this.url);
                console.log(err);
            }
    };
}
最佳回答

你们有两个问题:首先,this.onload没有在你把它分配给形象的时候加以界定。 您可以通过在存储<代码>onload的左手作为this的财产而加以确定。 第二个问题是,当<代码>上载 手稿功能被称作时,this并不适用于你认为的(事实上,它提到了刚刚装满的<代码>Image。 您需要将目前<代码>(ImageHolder)的标语和用法放在“密码”栏目中。

新法典:

var that = this;

this.myImage = new Image();
this.myImage.onload=function() {
    try {
        var d=document.getElementById("d");
        var mycanvas=d.getContext( 2d );
        mycanvas.drawImage(that.myImage, that.posx, that.posy, that.posw, that.posh);
    } catch(err) {
        console.log( Onload: could not draw image  +that.url);
        console.log(err);
    }
};
this.myImage.src = anImageURL;
问题回答

暂无回答




相关问题
selected text in iframe

How to get a selected text inside a iframe. I my page i m having a iframe which is editable true. So how can i get the selected text in that iframe.

How to fire event handlers on the link using javascript

I would like to click a link in my page using javascript. I would like to Fire event handlers on the link without navigating. How can this be done? This has to work both in firefox and Internet ...

How to Add script codes before the </body> tag ASP.NET

Heres the problem, In Masterpage, the google analytics code were pasted before the end of body tag. In ASPX page, I need to generate a script (google addItem tracker) using codebehind ClientScript ...

Clipboard access using Javascript - sans Flash?

Is there a reliable way to access the client machine s clipboard using Javascript? I continue to run into permissions issues when attempting to do this. How does Google Docs do this? Do they use ...

javascript debugging question

I have a large javascript which I didn t write but I need to use it and I m slowely going trough it trying to figure out what does it do and how, I m using alert to print out what it does but now I ...

Parsing date like twitter

I ve made a little forum and I want parse the date on newest posts like twitter, you know "posted 40 minutes ago ","posted 1 hour ago"... What s the best way ? Thanx.

热门标签