Setting opacity of html elements in different browsers

后端 未结 4 1351

I need to set an HTML object\'s opacity in JavaScript in all the browsers.

In Firefox I do it with line:

imageobje         


        
4条回答
  •  南方客
    南方客 (楼主)
    2020-12-15 22:31

    img.style.opacity = .5; //For real browsers;
    img.style.filter = "alpha(opacity=50)"; //For IE;
    

    You don't need to sniff the user agent, just set both values as browsers will ignore the irrelevant one.

提交回复
热议问题