Reputation: 1630
I found this code snippet and have following questions:
js fiddle in firefox only
js
$(document).ready(function(){
window.SineWave = SineWave = function() {
this.css = function(p) {
s = Math.sin((p-1)*50);
x = (100 - p*100) * 10;
y = s * 20;
return {top: y + "px", left: x + "px"};
}
}
window.loop = loop = function(){
$("#nyan").stop().animate(
{path: new SineWave},
50000,
"linear"
);
}
loop();
});
Upvotes: 0
Views: 434
Reputation: 288000
What does the p stand for in function(p)?
It's just an argument name.
Then, if you call the function like this.css(123)
, p
will become 123
.
What does
{path: new SineWave}
mean, what does path stand for?
I creates an object which has a property "path"
.
For example
var obj = {
a: 123
}
obj.a; // 123
abj['a']; // 123
In your case, the value is another object (instead of number 123
) which is an instance of SineWave
constructor. That means it inherits properties and methods from SineWave.prototype
.
What is the
stop()
goof for in the example code?
.stop()
is a jQuery method which stops the currently-running animation on the matched elements.
Upvotes: 3