2011-06-20 29 views
0

我试图在mouseenter上添加一张幻灯片,然后在mouseleave上滑动到正在使用图像交换脚本使用悬停功能的多个li类。我如何在mouseenter上滑动li类并在mouseleave上滑动?

<script type> 
$(document).ready(function() { 
    $('#thumb ul li a').hover(
      function() { 
       var currentBigImage = $('#gallery img').attr('src'); 
       var newBigImage = $(this).attr('src'); 
       var currentThumbSrc = $(this).attr('rel'); 
       switchImage(newBigImage, currentBigImage, currentThumbSrc); 
      }, 
      function() {} 
      ); 
      function switchImage(imageHref, currentBigImage, currentThumbSrc) { 
       var theBigImage = $('#gallery img'); 
       if (imageHref != currentBigImage) { 
       theBigImage.fadeOut(250, function(){ 
        theBigImage.attr('src', imageHref).fadeIn(250); 
        var newImageDesc = $("#thumb ul li a img[src='"+currentThumbSrc+"']").attr('alt'); 
        $('p#desc').empty().html(newImageDesc); 
       }); 
      } 
    } 
}); 
</script 

当我尝试使用下面在同一个脚本上面那样的剧本,下$('#thumb ul li a').hover(,它打破了交换图像和李类不滑动或做任何现有的悬停功能。

$(document).ready(function() { 
    $('#thumb ul li a').hover(
     function(){ 
      $(this).stop().animate({left:'20px'}, 500) 
     }, 
     function(){ 
      $(this).stop().animate({right:'20px'}, 500) 
}); 

我应该运行单独的脚本,一个交换图像和另一个滑动,我定义为李班#thumb ul li a下的链接?谢谢!

回答

1

而不是使用悬停两套绑定的,你为什么不尝试使用:

$('#thumb ul li a').bind("mouseenter", function() {}); 

$('#thumb ul li a').bind("mouseleave", function() {}); 

您的一组功能之一?

您也可以尝试使用您的绑定命名空间,如:

.bind("mouseenter.name1", function() {}) 
.bind("mouseenter.name2", function() {}) 
.bind("mouseleave.name1", function() {}) 
.bind("mouseleave.name2", function() {}) 
+0

无法得到它与这个无论是工作,我猜它是与剧本我已经运行。 – dcd0181

相关问题