[英]I want my jQuery animation to work only once
I want this to work only once. 我希望这只能工作一次。 For now, my scroll top always work and so it's impossible to scroll down my page. 现在,我的滚动顶部始终有效,因此无法向下滚动页面。
$(function() {
$(".showhover").hover(
function() {
$('div.mouseover').show(),
$("html, body").animate({scrollTop: $('div.mouseover').innerHeight() });
});
});
You could use one()
, but hover()
is a custom function in jQuery packaging mouseenter and mouseleave together, and doing one('hover')
would attach to the hover
event, which is not recommended. 您可以使用one()
,但hover()
是jQuery打包mouseenter和mouseleave中的自定义函数,并且执行one('hover')
将附加到hover
事件,这是不推荐的。
When using mouseenter / mouseleave you have to revert the functionality yourself : 使用mouseenter / mouseleave时,您必须自己恢复功能:
$(function() {
$(".showhover").one({
mouseenter: function() {
$('div.mouseover').show(),
$("html, body").animate({scrollTop: $('div.mouseover').innerHeight() });
},
mouseleave: function() {
$('div.mouseover').hide(),
}
});
});
Try one('mouseenter mouseleave'
, hover is a pseudo event for the combination of mouseenter and mouseleave. 尝试one('mouseenter mouseleave'
,悬停是用于mouseenter和mouseleave组合的伪事件。
$(".showhover").one('mouseenter mouseleave', function(e) {
$('div.mouseover').toggle();
if(e.type === 'mouseenter')
$("html, body").animate({scrollTop: $('div.mouseover').innerHeight() });
});
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.