2012-11-20 67 views
2
$(function(){ 
    $("#top-img").hover(function(){ 
    $(this).stop().animate({height:"400px"},{queue:false,duration:700}); 
     }, 

     function() { 
    $(this).stop().animate({height:"300px"},{queue:false,duration:700}); 
    }); 
}); 

这是我使用的代码,它的大部分很简单。当我将鼠标悬停在div #top-img上时,它会从300px的高度(在CSS中设置)开始,并将其设置为高度400px如何在悬停高度变化时为此添加延迟?

我想稍有延迟,使

  1. 人们不得不悬停在它的第二个,然后再运行和
  2. 你必须关闭它移到了第二它可以追溯到 前300px

回答

2

查看HoverIntent jQuery插件。我曾经使用它,并且它非常易于使用和实施

0

这类作品,但问题是当它悬停和停留很多次时,它并没有结束,只是继续上下。所以我需要一些如何添加我需要的两个。 。

$(document).ready(function(){ 
    $("#top-img").hover(function(){ 
    $(this).delay(400).animate({height:400},1000); 
},function(){ 

    $(this).delay(300).animate({height:300},500); 
    }); 
});