Read and write transparency in IE

Source: Internet
Author: User

First, to obtain transparency

Ele.filters.alpha

Returns an object of all filters for an element, which can be obtained on the basis of opacity.

But it seems that ele.filters can only store the first filter, and when we put Alpha in the second place, we can't get it, and here's the validation.

#q {            font-size:20px;             float : Left;            Filter:alpha (opacity=50), DropShadow (Color=black, offx=10px, offy=10px, positive=Positive);} Console.dir (Q.currentstyle.filter); Console.dir (q.filters);

The results are as follows:

So, we try to use Style.filter to get string operations!

Second, set the transparency

Setting transparency is a bit of a hassle and we need to address the following three questions:

    1. User incoming value multiplied by 100
    2. IE6, 7, element only triggers haslayout to make transparency effective
    3. IE8, setting the opacity to 100 causes the text to blur and needs to be clear about the filter

Problem solving:

1. The first problem, the solution is relatively simple, the code is as follows

Value= (value>0.999): (value<0.001) 0:value*100

2. The second question, we detect whether the element triggered the haslayout, if not, set his zoom property to 1

3. The third problem, when there are multiple filters, we only clear the transparent part

var rfilters=/[\w:\.] +\ ([^)]+]\)/g;     var filter=ele.currentstyle.filter| | ele.style.filter| | "" ;    Value=style.filter=filter.replace (rfilters,function(a) {        return /alpha/ I.test (a)? "" : A;})

Solve the above problems, we can formally set up! First, if our opacity can be obtained by node.filters, we can set it directly; if not, we can only use the string method.

var alpha=ele.filters.alpha| | Ele.filters[salpha]; // Ele.filters[salpha] to take care of the other two very long ways to set up a transparent filter, it's too    lazy to write if (Alpha) {        alpha.opacity=value;    } Else {        El.style.filter= (el.style.filter?el.style.filter+ ",": "") + "alpha (opacity=" +value+ ")";    }

Read and write transparency in IE

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.