S
S
Sergey Goryachev2015-11-08 14:16:56
css
Sergey Goryachev, 2015-11-08 14:16:56

How to make friends jQuery animate filter saturate?

Hello, I'm having some trouble with the jQuery animate filter saturate.

.block {
  filter: saturate(0%);
  background: url('http://hdwyn.com/wallpaper_1600x900/canada_british_columbia_mountain_lake_1600x900_hd-wallpaper-96912.jpg') center center / cover no-repeat transparent;
}

jQuery(document).ready(function($) {
  jQuery(".block").animate({'filter':'saturate(100%)'},2000);
})

Please help me find the error. If it is implemented at all)

Answer the question

In order to leave comments, you need to log in

1 answer(s)
D
Denis, 2015-11-08
@webirus

$(function () {

    $({saturate: 0}).animate({saturate: 100}, {
        duration: 2000,
        easing: 'swing', // linear
        step: function () {
            $('.block').css({
                '-webkit-filter': 'saturate(' + this.saturate + '%)',
                    'filter': 'saturate(' + this.saturate + '%)'
            });
        }
    });

});

Play in the sandbox - jsfiddle.net/Deonis/e1ukq884
PS By the way, it's not necessary to do this in JS. You can simply add a class where the filter values ​​will be 100% and animate using transition or animation.

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question