[英]Sticky on state for current page for javascript menu effect
I've created a hover effect for my website navigation. 我为网站导航创建了一个悬停效果。 http://www.preview.brencecoghill.com/ http://www.preview.brencecoghill.com/
I have got the effect to work as desired for all aspects accept one - I can't get the orange square to stay down for the currently selected page 我已经按照各个方面的要求进行了工作, 我无法让橙色方块停留在当前选中的页面上
How can I make this effect sticky for the current page that I am on? 如何使该效果对我当前所在的页面具有粘性? I'm fairly new to javascript - so I'm sure this is something fairly straight forwards - but I can't figure out how to make this work. 我对javascript还是很陌生-所以我确定这是相当简单的事情-但我不知道该如何做。
The website is based in Wordpress, and is outputting a class ".current_page_item" on the menu - so I am sure that this could be used to identify the menu item and stop the javascript firing if this item is hovered over? 该网站基于Wordpress,并在菜单上输出类“ .current_page_item” -因此,如果将鼠标悬停在菜单项上,我可以确定该菜单项可以用于识别菜单项并停止javascript触发?
I based the technique on the details available here: http://line25.com/tutorials/how-to-create-a-cool-animated-menu-with-jquery 我根据以下详细信息提供了该技术: http : //line25.com/tutorials/how-to-create-a-cool-animated-menu-with-jquery
I've pasted the javascript I have used on my website here to help you see what I'm doing: 我在这里粘贴了我在网站上使用过的javascript,以帮助您了解自己在做什么:
jQuery(document).ready(function () {
jQuery("#main-nav > li > a").addClass("js");
jQuery("#main-nav > li > a").hover(
function () {
jQuery(this).stop(true, true).animate({ backgroundPosition: "(0 -20)" }, 200);
jQuery(this).animate({ backgroundPosition: "(0 -5px)" }, 150);
},
function () {
jQuery(this).animate({ backgroundPosition: "(0 -100px)" }, 200);
}
);
});
exclude current-menu-item class from selector: 从选择器中排除当前菜单项类:
jQuery(document).ready(function () {
var nav=jQuery("#main-nav > li:not(.current-menu-item) > a");
nav.addClass("js");
nav.hover(
function () {
jQuery(this).stop(true, true).animate({ backgroundPosition: "(0 -20)" }, 200);
jQuery(this).animate({ backgroundPosition: "(0 -5px)" }, 150);
},
function () {
jQuery(this).animate({ backgroundPosition: "(0 -100px)" }, 200);
}
);
});
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.