1

I'm trying to add several css filters dynamicaly via Jquery.

So I have one slider for the brightness and another one for the contrast.

I want them both to modify a single div.

I can easily do this with one filter but I got some difficulties getting the value of both sliders and apply them on this single div.

I tried this, but the behaviour is odd

HTML :

<input class="brightness" type="range" min="0" max="100" value="100">
<input class="saturation" type="range" min="0" max="100" value="100">
<div></div>

Jquery :

$('input').change(function(){

    var $brightness_value = $('.brightness').val(),
        $saturation_value = $('.contrast').val(),
        $brightness_string = "brightness("+$brightness_value+"%)",
        $saturation_string = "saturate("+$saturation_value+")";


    $('div').css("-webkit-filter",$brightness_string+$saturation_string);
});

Any ideas ?

Thanks a lot !

3
  • You have a typo: $('.brighness') is missing the t. Is that in the real code or just a copying error? Commented Feb 12, 2014 at 19:54
  • Sadly just a copying error Commented Feb 12, 2014 at 19:56
  • you're trying to do this? jsfiddle.net/DYjw8 Commented Feb 12, 2014 at 20:01

1 Answer 1

1

You simply forgot to put the % to the value of saturate :

$saturation_string = "saturate("+$saturation_value+"%)";

http://jsfiddle.net/DYjw8/3/

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.