I am making an animation and I have found the following pen
:
CodePen
Code of pen
:
$({percentage: 0}).stop(true).animate({percentage: value}, {
duration : 2000,
easing: "easeOutExpo",
step: function () {
// percentage with 1 decimal;
var percentageVal = Math.round(this.percentage * 10) / 10;
$el.text(percentageVal + '%');
}
})
Selector:
$({percentage: 0})
.stop(true)
.animate({percentage: value}, {...});
- That changes?
- What is it for?
- In case of specifying properties of
jQuery
, what does the ofpercentage
?
I suppose it jquery
will have a JSON
properties and they will be changed in this way, but I had not seen it before.
$({percentage: 0})
It is the context in which the animation will work and when you indicate what the property is in the methodanimate()
, it will look for the indicated property on the context and apply the animation to it.If you look closely, you will notice how the body of
step()
is usedthis
to access the propertyporcentage
defined in the object passed by the jquery constructor, which is the context:TL;DR
{percentage: 0}
represents the context sent to the jquery constructor..animate({percentage: value},{})
represents the property to animate based on the context.