2013-08-01 27 views
0

我正在使用以下代碼進行懸停。但此代碼不適用於ajaxload。JavaScript上懸停不工作的Ajax負載?

<script type="text/javascript"> 
jQuery(document).ready(function(){ 
    jQuery('.products-grid .item').hover(function(){ 
     jQuery(this).find('.pro-review').animate({bottom:'0'}, 200); 
     jQuery(this).find('.pro-view').show(); 
    }, function(){ 
     jQuery(this).find('.pro-review').stop(true,true).animate({bottom:'-37'}, 200); 
     jQuery(this).find('.pro-view').hide(); 
    }); 
)}; 
</script> 

我找到替代這個像下面

<script type="text/javascript"> 
     jQuery(document).on("hover",".products-grid .item", function() { 
      jQuery(this).find('.pro-review').animate({bottom:'0'}, 200); 
      jQuery(this).find('.pro-view').show(); 
     }); 

</script> 

但我沒有找到如何解決第二功能。

, function(){ 
     jQuery(this).find('.pro-review').stop(true,true).animate({bottom:'-37'}, 200); 
     jQuery(this).find('.pro-view').hide(); 
    }); 

如何爲第二個功能是我使用的第一個功能

+0

添加另一個監聽器'mouseleave',應該做的伎倆 – NoLifeKing

回答

1

您可以使用mouseleavemouseenter,而不是hover與關聯像.on("hover",".products-grid .item", function()一些事情。

jQuery(document).on("mouseleave",".products-grid .item", function() { 
     jQuery(this).find('.pro-review').animate({bottom:'0'}, 200); 
     jQuery(this).find('.pro-view').show(); 
}); 


jQuery(document).on("mouseenter",".products-grid .item", function() { 
     jQuery(this).find('.pro-review').stop(true,true).animate({bottom:'-37'}, 200); 
    jQuery(this).find('.pro-view').hide(); 
}); 

,也可混合mouseentermouseleave

$(document).on({ 
    mouseenter: function() { 
     jQuery(this).find('.pro-review').animate({bottom:'0'}, 200); 
     jQuery(this).find('.pro-view').show(); 
    }, 

    mouseleave: function() { 
     jQuery(this).find('.pro-review').stop(true,true).animate({bottom:'-37'}, 200); 
     jQuery(this).find('.pro-view').hide(); 
    } 
}, '.products-grid .item'); 
+0

感謝help.It工作對我來說 – Muk

+0

歡迎您。 – Adil

2

'hover'實際上不是它自己的事件,而是一個shorthand for 2 others

調用$(selector).hover(handlerIn, handlerOut)是簡寫:

$(selector).mouseenter(handlerIn).mouseleave(handlerOut); 

對於委託綁定,您可以直接指定它們:

jQuery(document).on({ 
    'mouseenter': function(){ 
     jQuery(this).find('.pro-review').animate({bottom:'0'}, 200); 
     jQuery(this).find('.pro-view').show(); 
    }, 
    'mouseleave': function(){ 
     jQuery(this).find('.pro-review').stop(true,true).animate({bottom:'-37'}, 200); 
     jQuery(this).find('.pro-view').hide(); 
    } 
}, '.products-grid .item');