How to add alpha filter to any HTML element and keep the other filters in IE?

前端 未结 3 1213
误落风尘
误落风尘 2020-12-20 21:11

If I have this HTML


Then this javascript works in IE6

         


        
3条回答
  •  一生所求
    2020-12-20 21:53

    Unfortunately, it seems to me you can only add new elements through the style.filter property, with filters you can only manipulate already existing ones.

    filter is a collection object, you can find the docs here: filters Collection. It gives you a nice and easy way to play with your existing filters, you can turn them on and off (enabled), etc.

    For example, you can use

    obj.filters.item("DXImageTransform.Microsoft.Alpha").opacity=20;
    

    or (if alpha was you first filter declaration)

    obj.filters.item(0).opacity=20;
    

    CLASSES

    Most of the time you're better off storing your filter declarations under certain classes in your CSS, and only using JS to assign the right classes instead of manipulating style values directly.

提交回复
热议问题