简体   繁体   English

这行JQuery代码意味着什么?

[英]What does this line of JQuery code mean?

I came across this post on this site with a jFiddle showing a following menu for JQUery, well I saw this piece of syntax I can't figure out. 我在这个网站上看到了这个帖子,其中一个jFiddle显示了JQUery的以下菜单,我看到这段语法我无法弄清楚。

JFiddle: http://jsbin.com/oxajeq/3/edit?html,css,js,console,output JFiddle: http ://jsbin.com/oxajeq/3/edit?html,css,js,console,output

Line of code I do NOT understand 代码行我不明白

$('#mini-logo')[logoSH](300);

I know the first part selects the element with id of mini-logo, but I have no idea what the rest of the syntax is! 我知道第一部分选择id为mini-logo的元素,但我不知道其余的语法是什么! in the code, [logoSH] can become show or hide, while the () at the end means the duration. 在代码中,[logoSH]可以显示或隐藏,而末尾的()表示持续时间。 However, I can't find any example of anything using this syntax. 但是,我找不到任何使用此语法的示例。 I also googled for CSS3, JQUery, transitions, effects, animations, anything of what this might be and no luck. 我还搜索了CSS3,JQUery,过渡,效果,动画,这可能是什么,没有运气。 I find stuff that are methods, and others that are not methods but take parameters, but nothing like this code. 我发现的东西是方法,而其他的不是方法,而是参数,但没有像这个代码。 I know that what ever is inside [] is not a method, but I can't figure out what they are. 我知道里面的东西不是一种方法,但我无法弄清楚它们是什么。 thanks in advance for any help. 提前感谢您的帮助。

This construct is based on the bracket notation to access properties. 此构造基于括号表示法来访问属性。 It allows here a dynamic selection of the method to apply ( show or hide ). 它允许动态选择要应用的方法( showhide )。

logoSH is either "show" or "hide" . logoSH"show""hide"

Which means your line is either 这意味着你的行也是

$('#mini-logo')["show"](300); or $('#mini-logo')["hide"](300); $('#mini-logo')["hide"](300);

which you can also read as 你也可以读作

$('#mini-logo').show(300); or $('#mini-logo').hide(300); $('#mini-logo').hide(300);

This is a common construct, that you may also find with a ternary operator: 这是一个常见的构造,您也可以使用三元运算符找到它:

$('#mini-logo')[someBool ? "show" : "hide"](300);

Note: were there not the duration, you could have use the toggle function which takes a boolean as argument. 注意:如果没有持续时间,您可以使用以布尔值作为参数的toggle函数。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM