What does $({})
in jQuery mean ? I saw this on victmo response on this question : Possible to fade out div border?
jQuery中的$({})是什么意思?我在victmo的回复中看到了这个问题:是否可以淡出div边框?
He used $({alpha:1}).animate({alpha:0})
how this is affecting the DOM and what happens literally?
他使用了$({alpha:1}).animate({alpha:0})这如何影响DOM以及字面上发生的情况?
1 个解决方案
#1
6
What does $({ }) in jQuery mean ?
jQuery中的$({})是什么意思?
It means "pass an empty object to jQuery
and create a jQuery object from it".
它的意思是“将一个空对象传递给jQuery并从中创建一个jQuery对象”。
how this is affecting the DOM and what happens literally?
这是如何影响DOM的?
It doesn't affect the DOM at all, it simply changes the property value of the object {alpha:1}
over time.
它完全不影响DOM,只是随时间改变对象{alpha:1}的属性值。
You can use some jQuery methods on plain objects as explained in the documentation. Although it seems to be a bit outdated since animate
is not listed there. But it works indeed:
如文档中所述,可以在普通对象上使用jQuery方法。虽然它看起来有点过时,因为动画没有在那里列出。但它确实工作:
> $({alpha:1}).animate({alpha:0}, {step: function() { console.log(this.alpha); }})
1
0.9965342284774632
0.9870866934849247
0.9730426794137726
0.9524135262330098
0.9242551074907518
0.8926584654403724
0.8563192594626027
...
#1
6
What does $({ }) in jQuery mean ?
jQuery中的$({})是什么意思?
It means "pass an empty object to jQuery
and create a jQuery object from it".
它的意思是“将一个空对象传递给jQuery并从中创建一个jQuery对象”。
how this is affecting the DOM and what happens literally?
这是如何影响DOM的?
It doesn't affect the DOM at all, it simply changes the property value of the object {alpha:1}
over time.
它完全不影响DOM,只是随时间改变对象{alpha:1}的属性值。
You can use some jQuery methods on plain objects as explained in the documentation. Although it seems to be a bit outdated since animate
is not listed there. But it works indeed:
如文档中所述,可以在普通对象上使用jQuery方法。虽然它看起来有点过时,因为动画没有在那里列出。但它确实工作:
> $({alpha:1}).animate({alpha:0}, {step: function() { console.log(this.alpha); }})
1
0.9965342284774632
0.9870866934849247
0.9730426794137726
0.9524135262330098
0.9242551074907518
0.8926584654403724
0.8563192594626027
...