简体   繁体   English

将鼠标悬停在子菜单上时防止在导航项上出现jquery背景图像精灵动画

[英]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.

相关问题 jQuery hover - 当光标没有悬停时,子菜单保持打开状态,并在您悬停时隐藏它 - jQuery hover - sub-menu stay open while the cursor is not hovering, and hides it when you hover 当鼠标悬停在菜单项上时,子菜单不会保持打开状态 - Sub-Menu not staying open when mouse hovers over Menu item jQuery会在鼠标悬停时在链接上添加背景颜色,而鼠标悬停子菜单时会保留背景? - jQuery adding background color on link when hover, background stay while mouse hovers sub-menu? jQuery bgColor动画:进入子菜单时保持活动状态 - jQuery bgColor animation: keep active when going down a sub-menu 当不再将鼠标悬停在图像上时,jQuery动画停止 - Jquery animation stop when not hovering anymore over image 防止具有“子菜单”类的 ul 元素成为 Wordpress 菜单中列表项的子元素 - Preventing an ul element with the class 'sub-menu' from being child element of a list item in a Wordpress menu 悬停时菜单项晃动 nav_drop_item - Menu item shaking when hovering nav_drop_item 使用jQuery动态添加子菜单指示器图像 - Add a sub-menu indicator image dynamically using jQuery 即使我将鼠标悬停在菜单按钮上,也保持下拉菜单可见,因为我仍然将鼠标悬停在子菜单链接上 - keep the dropdown menu visible even if i mouseout the menu button because i am still hovering over sub-menu links 展开jQuery-&gt;导航子菜单-&gt;子菜单 - Expand jQuery -> Navigation sub-menu -> sub-menu
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM