In Javascript how can I set rgba without specifying the rgb?

前端 未结 5 1147
旧巷少年郎
旧巷少年郎 2020-12-17 08:09

I have an HTML element whose background colour is set with rgba()

T

5条回答
  •  我在风中等你
    2020-12-17 08:51

    After some playing around, and the discovery of getComputedStyle, I have put together this.

    
    
      
        
        
      
      
        
    This is some content.
    • Make sure you define in your css your values, and cascade because RGBA is CSS3.
    • Also see that you can pass in a number >1 for alpha and it will divide by 100 for you (I hate working with decimals when thinking percentages).
    • Enjoy!

提交回复
热议问题