Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/powershell/13.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Javascript 我希望我的jQuery动画只工作一次_Javascript_Jquery - Fatal编程技术网

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()
是你在这里的朋友。从现在开始,他是的!