Jump to content
Search Community

Usage of CSSPlugin.registerSpecialProp in the right way

RolandSoos test
Moderator Tag

Warning: Please note

This thread was started before GSAP 3 was released. Some information, especially the syntax, may be out of date for GSAP 3. Please see the GSAP 3 migration guide and release notes for more information about how to update the code to GSAP 3's syntax. 

Recommended Posts

Version #2

 

Do I need to add this check if the start and end value are the same to prevent not necessary property change?

            if(start == value){
                return function(){

                };
            }
CSSPlugin.registerSpecialProp(
        "n2blur",
        function (target, value, tween) {
            var start = 0,
                match;
            if ((match = target.style.webkitFilter.match(/blur\((.+)?px\)/))) {
                start = parseFloat(match[1]);
            }
            if(start == value){
                return function(){

                };
            }
            var diff = value - start;
            return function (ratio) {
                target.style.webkitFilter = "blur(" + (start + diff * ratio) + "px)";
            };
        },
        0
    );
Link to comment
Share on other sites

Okay, I have added the conditions to handle prefixed and unprefixed browsers. It seemed for me that  that -moz -ms and -o prefixes are not used in any production release of the browsers...

    var blurProperty = false,
        element = document.createElement('div');
    if (element.style.webkitFilter !== undefined) {
        blurProperty = 'webkitFilter';
    } else if (element.style.filter !== undefined) {
        blurProperty = 'filter';
    }
    if (blurProperty) {
        CSSPlugin.registerSpecialProp(
            "n2blur",
            function (target, value, tween) {
                var start = 0,
                    match;
                if ((match = target.style[blurProperty].match(/blur\((.+)?px\)/))) {
                    start = parseFloat(match[1]);
                }
                if (start == value) {
                    return function () {

                    };
                }
                var diff = value - start;
                return function (ratio) {
                    target.style[blurProperty] = "blur(" + (start + diff * ratio) + "px)";
                };
            },
            0
        );
    }
  • Like 2
Link to comment
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...