I'm trying to change the saturate filter value from 1 to 5 and back to 1. I'm guessing the implementation of a variable in the getElementById
is completely wrong. What's the problem?
var up = true;
var value = 1;
var increment = 1;
var ceiling = 5;
function PerformCalc() {
if (up == true && value <= ceiling) {
value += increment
if (value == ceiling) {
up = false;
}
} else {
up = false
value -= increment;
if (value == 1) {
up = true;
}
}
function changesaturation(value) {
document.getElementById("s1").style.webkitFilter = "saturate(" value")";
}
}
setInterval(PerformCalc, 100);
<img src="image.jpg" id="s1" width="100%" height="1200px">
The nested function "changesaturation" doesn't seem necessary.
Also, string concatenation in JavaScript can be achieved with the Addition (+) operator.
Other than that, your code seems to work.
As Temani Afif mentioned, the effect can also be achieved with CSS animation.
Here's an example:
According to shouldiprefix, the "-webkit" vendor prefix is recommended at the time of this post.