How to get filter value for each effect with %
and px
and only numbers without %
and px
.
In the codec I have listed 3 filters (of course there may be more).
What is the best way?
<button onclick="myFunction()">Try it</button><br><br>
<img id="myImg"
src="https://www.roadrunnerrecords.com/sites/g/files/g2000005056/f/sample-4.jpg"
width="300"
height="300"
style="filter:grayscale(100%) blur(5px) brightness(150%)" />
function myFunction() {
var grayscale = document.getElementById("myImg").style.filter;
var blur = document.getElementById("myImg").style.filter;
var brightness = document.getElementById("myImg").style.filter;
alert("grayscale value = , blur value= , brightness value= "); //without % and px
alert("grayscale value = , blur value= , brightness value= "); //with % and px
}
function myFunction() {
var effects = document.getElementById("myImg").style.filter.split(" ");
var imgFilter = {};
for (var i = 0; i < effects.length; ++i) {
var split = effects[i].split("(");
imgFilter[split[0]] = split[1].substring(0,split[1].length-1);
}
alert("grayscale value = "+imgFilter.grayscale+" , blur value= "+imgFilter.blur+", brightness value= "+imgFilter.brightness);//with % and px
alert("grayscale value = "+imgFilter.grayscale.replace(/[^\d.]/g,"")+" , blur value= "+imgFilter.blur.replace(/[^\d.]/g,"")+", brightness value= "+imgFilter.brightness.replace(/[^\d.]/g,""));//without % and px
} // How to add Hue-rotate???