input class="gwd-input-13xh" type="range" min="0" max="50" value="25" id="slider" oninput="getInput(this.value, this.max)">
.img_1 {
position: absolute;
width: 180px;
height: 130px;
left: 62px;
top: 1px;
-webkit-filter: blur(5px);
opacity: .8;
}
.img_2 {
position: absolute;
width: 180px;
height: 130px;
left: 62px;
top: 1px;
-webkit-filter: blur(5px);
opacity: .8;
}
What I am trying to do is adjust the opacity and the filter at the same time depending on the slide. Here is the code that I have to perform said function:
function getInput(value, max) {
var img_1 = document.getElementById("img_1");
var img_2 = document.getElementById("img_2");
var sliderPercentage = (value / max).toFixed(2);
setOpacity(img_1, (1 - sliderPercentage));
setBlur(img_1, (10 * sliderPercentage).toFixed(2));
setOpacity(img_2, sliderPercentage);
setBlur(img_2, 10 - (10 * sliderPercentage).toFixed(2));
}
function setOpacity(ele, value) {
return ele.style.opacity = value;
}
function setBlur(ele, value) {
ele.setAttribute("style", "-webkit-filter:blur(" + value + "px)")
}
This code works great, although what happens is that when I use the `setBlur` function, it overrides the `setOpacity` function. When I remove the `setBlur` function the `setOpacity` function works.
I assume the problem is you are re-assigning the whole
style
attribute, so later alteration overrides the former. Replacingele.setAttribute("style", "...")
withele.style["-webkit-filter"] = "blur(" + value + "px)";
should fix your issue.