Superfish 打开选项“onInit”
在我的一些页面上,我希望 Superfish(菜单插件)在页面打开时默认展开第一级选项之一。我将此选项归因于 ul id =“me”,并尝试实现“onInit”功能,但它不起作用。有人可以看一下吗?谢谢。
jQuery(function(){
jQuery('ul.sf-menu').superfish({
onInit: function(){$('#me',this).show();},
});
});
On some of my pages I want Superfish (menu plugin) to unfold one of the first level options by default as soon as the page opens. I attributed this option ul an id="me", and trying to implement "onInit" function, but it does not work. Could someone please look? Thanks.
jQuery(function(){
jQuery('ul.sf-menu').superfish({
onInit: function(){$('#me',this).show();},
});
});
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
你有任何 JavaScript 错误吗?
您发布的代码片段可能存在问题:
onInit
都不会被调用。使用alert
或console.log
检查onInit
中的this
不是 DOMElement。它可能是一个 jquery 对象。检查console.log
另外,其中存在语法错误:对象文字中的最后一个属性后面不能跟逗号。
do you get any javascript errors?
possible problems with the snippet you posted:
onInit
does not get called for whatever reason. check withalert
orconsole.log
this
inonInit
is not a DOMElement. it might be a jquery object. check withconsole.log
plus, you have a syntax error in there: the last property in an object literal must not be followed by a comma.
好的,CSS 部分很简单。它不使用任何“可见性”值,而是更改
从“top:-999em”(隐藏)到“top:2.5em”(显示)的框位置。
我为我创建了一个单独的类,它只是 Superfish“可显示”框的副本:
现在如果禁用 JS,它就可以工作,但是当启用 JS 时,所有选项都会折叠起来。
这只是我这次尝试的众多变体之一:
而且它根本没有任何效果,就好像这个类不存在一样。
如果我尝试:
单词“hello”出现在鼠标悬停而不是子菜单上 - 但在鼠标悬停时出现,而不是“onInit”。
Ok, the CSS part was easy. It does not use any "visibility" values, instead it changes
a box position from "top:-999em" (to hide) to "top:2.5em" (to display).
I created a separate class for my , which is just a copy from Superfish "displayable" boxes:
Now it works if JS is disabled but when JS is enabled all options get collapsed anyway.
Here is just one of the many variants i tried this time:
and it has no effect at all, as if this class does not exists.
If I try:
the word 'hello' appears on mouseover instead of submenu - but on mouseover, not "onInit".