多个下拉菜单,一个 JQuery 脚本
我一直在使用由 Skyrocket Labs 开发并由 Peter Hinton 改进的 jDiv 下拉菜单。它适用于同一页面上的多个菜单,只要您使用不同的标识符复制代码(#nav1 触发 #hidden-menu1,#nav2 触发 #hidden-nav2 等)。
var hide1 = false;
$("#nav1").hover(function(){
if (hide1) clearTimeout(hide1);
$("#hidden-nav1").show();
}, function() {
hide1 = setTimeout(function() {$("#hidden-nav1").hide();});
});
$("#hidden-nav1").hover(function(){
if (hide1) clearTimeout(hide1);
}, function() {
hide1 = setTimeout(function() {$("#hidden-nav1").hide();});
$("#hidden-nav1").stop().show();
});
我正在尝试弄清楚如何重写代码,以便它可以“发现”悬停链接的 navX 的数值并触发适当的隐藏 navX div。
I have been playing with the jDiv dropdown menu developed by Skyrocket Labs and improved by Peter Hinton. It works well for multiple menus on the same page, as long as you replicate the code with different identifiers (#nav1 triggers #hidden-menu1, #nav2 triggers #hidden-nav2, etc).
var hide1 = false;
$("#nav1").hover(function(){
if (hide1) clearTimeout(hide1);
$("#hidden-nav1").show();
}, function() {
hide1 = setTimeout(function() {$("#hidden-nav1").hide();});
});
$("#hidden-nav1").hover(function(){
if (hide1) clearTimeout(hide1);
}, function() {
hide1 = setTimeout(function() {$("#hidden-nav1").hide();});
$("#hidden-nav1").stop().show();
});
I am trying to sort out how to rewrite the code so that it can, "discover" the numerical value of the navX linked hovered and trigger the appropriate hidden-navX divs.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
这是一个工作
JSFiddle DEMO
我删除了所有 ID 只是为了展示如何简单和条纹代码和功能也一样,只需使用类。
如果需要使用您的 ID,您可以撤消它们,但保持所有不变。
如果您需要有关代码的解释,我可以注释每一行。
这是新的/更改的 Jquery:
使用 COMMENTS
为了帮助您用几句话理解:我们添加自动为每个“li”及其对应的“下拉菜单”调用相同的自定义类:“.connectedN”,
其中“N”是递增的数字。
比我们刚才说的:如果悬停的“li”是类“connected3”这意味着我们刚刚将鼠标悬停在第三个“li”上,然后我们将打开具有相同类的“.dropdown”。
Here is a working
JSFiddle DEMO
I removed ALL ID's just to show how easy and striped can be the code and functional too, just using classes.
You can undo your ID's if you need to use them, but leave all unchanged.
If you need explanation about the code I can comment each line.
Here is the new/changed Jquery:
With COMMENTS
To help you understand in few words: We add automatically a SAME custom class to each 'li' and his corespondent 'dropdown' called: '.connectedN',
where 'N' is an incremented number.
Than we just say: if the hovered 'li' is class 'connected3' that means we just hovered the 3th 'li' , and we'll go to open the '.dropdown' that have the SAME class.
尝试
Try