Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/jquery/82.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/8/variables/2.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
两个相互干扰的jquery函数_Jquery - Fatal编程技术网

两个相互干扰的jquery函数

两个相互干扰的jquery函数,jquery,Jquery,我有两个jquery函数,它们做着类似的事情(一个用于mouseover,另一个用于click),它们似乎相互干扰。第一种是在悬停状态下使用jquery ui switchclass更改背景。这也会打开一个子菜单。单击子菜单中的链接时,会触发一个单击功能,该功能将删除上一个菜单。并使用switchclass更改该背景。问题是,只要移动鼠标,鼠标就会弹出鼠标并将背景更改回默认背景 这是鼠标盖 $('.hoverbg').mouseover( function(){ var ne

我有两个jquery函数,它们做着类似的事情(一个用于mouseover,另一个用于click),它们似乎相互干扰。第一种是在悬停状态下使用jquery ui switchclass更改背景。这也会打开一个子菜单。单击子菜单中的链接时,会触发一个单击功能,该功能将删除上一个菜单。并使用switchclass更改该背景。问题是,只要移动鼠标,鼠标就会弹出鼠标并将背景更改回默认背景

这是鼠标盖

     $('.hoverbg').mouseover(
  function(){
   var newimg = $(this).attr('data-bgsrc');
   $('#bg img[src="'+newimg+'"]').switchClass("inactive", "active", 0, "easeInOutQuad");
   $('#bg img[src!="'+newimg+'"]').switchClass("active", "inactive", 0, "easeInOutQuad");
  });
$('.nav').mouseout
 (function(){
    if ($('#sitewrapper').hasClass("c"))
    {
      event.stopImmediatePropagation()
    }
    else
    {
      $('#bg img[src="images/bg.jpg"]').switchClass("inactive", "active", 0, "easeInOutQuad");
      $('#bg img[src!="images/bg.jpg"]').switchClass("active", "inactive", 0, "easeInOutQuad");
    }
  });
这里是点击事件。它隐藏了作为mouseout一部分的nav类。从技术上讲,我想这会让你从菜单中删除,但我让它在sitewrapper div中添加一个类,如果该类存在,就停止

    $('a#navclick').click(function(){
 var iclick = $(this).attr('data-iclick');
 var clickimg = $(this).attr('click-data-bgsrc');
 if ($('#topId').hasClass('.topOn'))
 {
   $('#bg img[src="'+clickimg+'"]').switchClass("inactive", "active", 0, "easeInOutQuad");
   $('#bg img[src!="'+clickimg+'"]').switchClass("active", "inactive", 0, "easeInOutQuad");
 }
 else
 {
 $('#sitewrapper').addClass("c");
 $('img.logo').hide("drop", {direction: "down"}, 1000);
 $('.nav').hide("drop", {direction: "down"}, 1000);
 $('#bg img[src="'+clickimg+'"]').switchClass("inactive", "active", 0, "easeInOutQuad");
 $('#bg img[src!="'+clickimg+'"]').switchClass("active", "inactive", 0, "easeInOutQuad");
 $('#topId').addClass('topOn');
 $('#topId').show("slide", {direction:"up"}, 1000);
 }
 });

我已经弄明白了。点击功能很好,看起来像这样

    $('a#navclick').click(function(){
 var iclick = $(this).attr('data-iclick');
 var clickimg = $(this).attr('click-data-bgsrc');
 if ($('#topId').hasClass('topOn'))
 {
   $('#bg img[src="'+clickimg+'"]').switchClass("inactive", "active", 0, "easeInOutQuad");
   $('#bg img[src!="'+clickimg+'"]').switchClass("active", "inactive", 0, "easeInOutQuad");
 }
 else
 {
 $('#topId').addClass('topOn');
 $('img.logo').hide("drop", {direction: "down"}, 1000);
 $('.nav').hide("drop", {direction: "down"}, 1000);
 $('#bg img[src!="'+clickimg+'"]').switchClass("active", "inactive", 0, "easeInOutQuad");
 $('#bg img[src="'+clickimg+'"]').switchClass("inactive", "active", 0, "easeInOutQuad");
 $('#topId').show("slide", {direction:"up"}, 1000);
 }
 });
     $('.hoverbg').mouseenter(
  function(){
   var newimg = $(this).attr('data-bgsrc');
   $('#bg img[src="'+newimg+'"]').switchClass("inactive", "active", 0, "easeInOutQuad");
   $('#bg img[src!="'+newimg+'"]').switchClass("active", "inactive", 0, "easeInOutQuad");
  });
$('.hoverbg').mouseleave
 (function(){
   if(jQuery('#topId').hasClass('topOn'))
   {
     jQuery('.hoverbg').stop();
   }
   else
   {
    $('#bg img[src="images/bg.jpg"]').switchClass("inactive", "active", 0, "easeInOutQuad");
    $('#bg img[src!="images/bg.jpg"]').switchClass("active", "inactive", 0, "easeInOutQuad");
   }
 });
鼠标悬停函数需要一个if语句来在单击发生时停止它。因此,我让click事件将一个类添加到一个名为topOn的可见div中。然后添加了一个if语句,用于检查该div是否具有topOn类。看起来是这样的,

    $('a#navclick').click(function(){
 var iclick = $(this).attr('data-iclick');
 var clickimg = $(this).attr('click-data-bgsrc');
 if ($('#topId').hasClass('topOn'))
 {
   $('#bg img[src="'+clickimg+'"]').switchClass("inactive", "active", 0, "easeInOutQuad");
   $('#bg img[src!="'+clickimg+'"]').switchClass("active", "inactive", 0, "easeInOutQuad");
 }
 else
 {
 $('#topId').addClass('topOn');
 $('img.logo').hide("drop", {direction: "down"}, 1000);
 $('.nav').hide("drop", {direction: "down"}, 1000);
 $('#bg img[src!="'+clickimg+'"]').switchClass("active", "inactive", 0, "easeInOutQuad");
 $('#bg img[src="'+clickimg+'"]').switchClass("inactive", "active", 0, "easeInOutQuad");
 $('#topId').show("slide", {direction:"up"}, 1000);
 }
 });
     $('.hoverbg').mouseenter(
  function(){
   var newimg = $(this).attr('data-bgsrc');
   $('#bg img[src="'+newimg+'"]').switchClass("inactive", "active", 0, "easeInOutQuad");
   $('#bg img[src!="'+newimg+'"]').switchClass("active", "inactive", 0, "easeInOutQuad");
  });
$('.hoverbg').mouseleave
 (function(){
   if(jQuery('#topId').hasClass('topOn'))
   {
     jQuery('.hoverbg').stop();
   }
   else
   {
    $('#bg img[src="images/bg.jpg"]').switchClass("inactive", "active", 0, "easeInOutQuad");
    $('#bg img[src!="images/bg.jpg"]').switchClass("active", "inactive", 0, "easeInOutQuad");
   }
 });

我可能错了,else部分中包含的click参数似乎没有改变firefox和explorer中的图像。你有没有想过为什么那样不行?