How to change the opacity (alpha, transparency) of an element in a canvas element after it has been drawn?

前端 未结 8 1152
庸人自扰
庸人自扰 2020-11-27 09:51

Using the HTML5 element, I would like to load an image file (PNG, JPEG, etc.), draw it to the canvas completely transparently, and then fade it i

8条回答
  •  天涯浪人
    2020-11-27 10:03

    Edit: The answer marked as "correct" is not correct.

    It's easy to do. Try this code, swapping out "ie.jpg" with whatever picture you have handy:

    
    
        
            
        
        
            
        
    
    

    The key is the globalAlpha property.

    Tested with IE 9, FF 5, Safari 5, and Chrome 12 on Win7.

提交回复
热议问题