Search code examples
javascripthtml5-canvaskineticjs

understanding the concept of changing an image source


I have a problem in understanding the concept of changing an image source. I have a function that create an image on stage .I want the image to be changed when the user clicks on it. can any one give me an example? Thanks for Help


Solution

  • Here's how to change the image when an node is clicked:

    • Listen for click events on the node.
    • In the click handler, change the node's image property to a new image object.
    • redraw the layer

    Example code:

    myNode.on('click',function(){
        this.image( newImageObject );
        layer.draw();
    }