2013-06-19 67 views
0

在JavaScript中,我想制定一个规则,以便.mouseover只会在第一次滚动时起作用。让.mouseover只在第一次滚动时才能工作

我该怎么做?

这里是我的代码:

$("#page3").mouseover(function(){ 
$("#htmlcss").animate({width: "90%"}, 500); 
$("#jqueryjavascript").animate({width: "40%"}, 500); 
$("#phpmysql").animate({width: "20%"}, 500); 
}); 

回答

1

我想你可以使用jQuery的解除绑定方法 - http://api.jquery.com/unbind/

只要打电话给鼠标悬停事件处理程序中的对象的解除绑定方法,它应该工作。

下面是一个例子:

$('div').mouseover(function(event){ 
    $(this).append('<br>Hi again!'); 
    $(this).unbind(event); 
}); 

我觉得你的代码应该改成这样的:

$("#page3").mouseover(function(event){ 
    $("#htmlcss").animate({width: "90%"}, 500); 
    $("#jqueryjavascript").animate({width: "40%"}, 500); 
    $("#phpmysql").animate({width: "20%"}, 500); 
    $(this).unbind(event); 
});