Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

baidu.dom.opacity method users 'opacity:' instead of 'opacity=' #315

Open
starandtina opened this issue Aug 18, 2012 · 0 comments
Open

baidu.dom.opacity method users 'opacity:' instead of 'opacity=' #315

starandtina opened this issue Aug 18, 2012 · 0 comments

Comments

@starandtina
Copy link

In the method of baidu.dom.opacity, and it set the opacity using filter with 'xxxxx(opacity__:xxx' instead of 'xxxxx(opacity=__'.
The problem is that if I set the opacity with this method, but I want to get the opacity using the baidu.dom.getStyle, and it won't work.
Frankly speaking, I can't figure out why there exists a method calling baidu.dom.opacity, do you want to provide a shortcut method? or other reasons?

baidu.dom.opacity = function(element, opacity){
    element = baidu.dom.g(element);

    if (!baidu.browser.ie) {
        element.style.opacity = opacity;
        element.style.KHTMLOpacity = opacity;
    } else {
        element.style.filter = "progid:DXImageTransform.Microsoft.Alpha(opacity:"+
            Math.floor(opacity * 100) +")";
    }
};
baidu.dom._styleFixer.opacity = baidu.browser.ie ? {
    get: function (element) {
        var filter = element.style.filter;
        return filter && filter.indexOf("opacity=") >= 0 ? (parseFloat(filter.match(/opacity=([^)]*)/)[1]) / 100) + "" : "1";
    },

    set: function (element, value) {
        var style = element.style;
        // 只能Quirks Mode下面生效??
        style.filter = (style.filter || "").replace(/alpha\([^\)]*\)/gi, "") + (value == 1 ? "" : "alpha(opacity=" + value * 100 + ")");
        // IE filters only apply to elements with "layout."
        style.zoom = 1;
    }
} : null;

thanks,

starandtina

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant