Javascript 我希望我的jQuery动画只工作一次
我只想让它工作一次。现在,我的滚动顶部总是工作,所以不可能向下滚动我的页面Javascript 我希望我的jQuery动画只工作一次,javascript,jquery,Javascript,Jquery,我只想让它工作一次。现在,我的滚动顶部总是工作,所以不可能向下滚动我的页面 $(function() { $(".showhover").hover( function() { $('div.mouseover').show(), $("html, body").animate({scrollTop: $('div.mouseover').innerHeight() }); }); }); 尝试one('mouseenter mouse
$(function() {
$(".showhover").hover(
function() {
$('div.mouseover').show(),
$("html, body").animate({scrollTop: $('div.mouseover').innerHeight() });
});
});
尝试one('mouseenter mouseleave')
,hover是mouseenter和mouseleave组合的伪事件
$(".showhover").one('mouseenter mouseleave', function(e) {
$('div.mouseover').toggle();
if(e.type === 'mouseenter')
$("html, body").animate({scrollTop: $('div.mouseover').innerHeight() });
});
您可以使用one()
,但是hover()
是jQuery中的一个自定义函数,它将mouseenter和mouseleave打包在一起,执行one('hover')
将附加到hover
事件,这是不推荐的
使用mouseenter/mouseleave时,您必须自己恢复功能:
$(function() {
$(".showhover").one({
mouseenter: function() {
$('div.mouseover').show(),
$("html, body").animate({scrollTop: $('div.mouseover').innerHeight() });
},
mouseleave: function() {
$('div.mouseover').hide(),
}
});
});
.one()
是你在这里的朋友。从现在开始,他是的!