javascript - Why do I get "X is not a function" in the following recursive function? -
i'm using following code animate opacity of element:
var opacity = 0 // starting opacity var step = 0.1 // step size var target = 1 // target value var time = 50 // delay in milliseconds // start timer loop, , record it's index var increaseopacity = setinterval(function () { // assuming selector works, set opacity $(`#pano-${index}`).attr({ opacity: opacity }) // increment opacity step size opacity += step // if reached our target value, stop timer if (opacity >= target) { clearinterval(increaseopacity) } }, time) $('.pano').attr({ opacity: 0 }) increaseopacity()
it works. however, uncaught typeerror: increaseopacity not function
every time run function.
why , how fix it?
however, uncaught typeerror: increaseopacity not function every time run function.
increaseopacity
not function object, identifier timer clearinterval
can stop , clear timer later.
why , how fix it?
you can remove function call since automatically invoked setinterval
method.
Comments
Post a Comment