[英]Preventing jquery background image sprite animation on nav item when hovering over sub-menu
I have the following script which handles the animation of a background image for items in my navigation bar: 我有以下脚本,用于处理导航栏中项目的背景图像动画:
$j(function() {
$j(".menu-item").find(".bottom_nav").hover(function () {
$j(this).animate( {
backgroundPosition : '0px 35px'}
, 300); }
, function () {
$j(this).animate( {
backgroundPosition : '0px 0px'}
, 600); }
);
});
This works fine, except that when the nav item has a submenu and the user hovers over the submenu I don't want the second animation in this function to fire, ie I would like the backgroundPosition to remain as '0px 35px'. 这项工作正常,但是当导航项具有子菜单并且用户将鼠标悬停在该子菜单上时,我不希望触发该函数中的第二个动画,即我希望backgroundPosition保持为“ 0px 35px”。 This would work as is, but the submenu is outside of .bottom_nav div.
这将按原样工作,但子菜单位于.bottom_nav div之外。 The structure of the markup for the menu/submenu is handled by a Wordpress theme and I'm not sure how to alter this.
菜单/子菜单的标记结构由Wordpress主题处理,我不确定如何更改。 Here's a screenshot that will give you an idea of the markup:
这是一个截图,可以让您对标记有所了解:
As you can see <ul class="sub-menu">
is outside of the .bottom_nav div. 如您所见,
<ul class="sub-menu">
在.bottom_nav div之外。
You can see the nav item in action on this page . 您可以在此页面上看到正在运行的导航项。 The second item in the navigation bar called "News" has a drop-down submenu, and I would like the background colour on the nav item "News" to stay green when hovering over this submenu.
导航栏中的第二项称为“新闻”,有一个下拉子菜单,我希望将导航项“新闻”上的背景色悬停在该子菜单上时保持绿色。
I sorted this by adding the following: 我通过添加以下内容对此进行了排序:
$j(function() {
$j(".sub-menu").hover(function () {
$j(this).closest('.menu-item').find(".bottom_nav").stop().animate( {
backgroundPosition : '0px 35px'}
, 300); }
, function () {
$j(this).closest('.menu-item').find(".bottom_nav").stop().animate( {
backgroundPosition : '0px 0px'}
, 600); }
);
});
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.