2011-03-29 41 views
0

我想在一个网站上运行这两个单独的脚本。这是他们看起来如何:jQuery冲突 - .load和悬停意图

<script type="text/javascript"> 
$(document).ready(function() { 

     var name = ""; 

     $(".home-roll-box").hover(function() { 
      name = $(this).attr("id"); 
      $("#image-"+name).stop().show().animate({ opacity: 1 }); 
     }, function() { 
      name = $(this).attr("id"); 
      $("#image-"+name).stop().animate({ opacity: 0 }); 
     }); 
     }); 
</script> 
<!--/Band Images--> 

<!--Navigation--> 
<script type="text/javascript"> 
     $.ajaxSetup ({ cache: false }); 

     $('ul.navigation li a').click(function() { 
     $('ul.navigation li.page_item.current_page_item').removeClass('current_page_item'); 
     $('ul.navigation li.page_item a.active').removeClass('active'); 
     $('#content-wrap').animate({ 
      top: "-2000px" 
     }, 1000); 

      var targetPage = $(this).attr('href'); 
      targetPage += " #content"; 

     setTimeout(function() { 
      $('#content-wrap').load(targetPage, function() { 
       $('#content-wrap').animate({ 
        top: "0px" 
       }, 1000); 
      }); 
     }); 
     $(this).addClass('active'); 
     return false; 
    }); 
</script> 

他们都单独工作,但不是在一起。它似乎是导致问题的第二个脚本底部的return false;

+0

'返回false;'防止click事件从“流血”到页面中的其他元素,还可以防止发生正常的点击行为(如跟随链接或提交表单)。你真的需要那个'返回假';那里? – 2011-03-29 12:21:10

+0

@理查德尼尔伊拉甘 - 谢谢。是的,如果不存在,页面会正常加载(没有Ajax效果)。 – Infocentre 2011-03-29 12:26:57

+0

啊,那么你只是想停止点击从实际上跟随到链接。在下面检查@rcravens的答案;这应该适合你。 – 2011-03-29 12:28:42

回答

0

尝试在单击处理程序添加EVT参数,然后调用

evt.preventDefault(); 

这里的差异一个很好的说明:http://fuelyourcoding.com/jquery-events-stop-misusing-return-false/

+0

对不起,@rcravens - 你将不得不在代码的位置更具体! – Infocentre 2011-03-29 12:27:51

+0

只需阅读您发布的链接。我在'evt.preventDefault();'中加入了''load'函数,尽管它似乎仍然会干扰另一个脚本...... – Infocentre 2011-03-29 12:38:53