我试图模仿powerpoint演示文稿的页脚。所以这是密码
$(function() { $('.presentation').on({ mouseleave: function() { setInterval(function () { if(!$("input").is(":focus") && !$(".presentation:hover").length > 0 && !$('.bp-controls').hasClass('show')){ $('.bp-controls').fadeOut(); $('.bp-controls').removeClass('show'); } }, 4000); }, mouseenter: function() { $('.bp-controls').fadeTo(500, 1, function() { // Animation complete. $('.bp-controls').addClass('show'); }); } }); });
<script src="https://cdnjs.cloudflare.com/ajax/libs/jquery/3.3.1/jquery.min.js"></script> <div class="presentation"> <img src="Main.png" width="50%"> <div class="bp-controls"><input type="number" pattern="[0-9]*"></div> </div>
您正在添加多个间隔。当你离开的时候你需要离开。也应该是个暂停,我怀疑你是否还想继续开火。
$('.presentation').on({ mouseleave: function() { this.timer = setTimeout(function () {}, 4000); }, mouseenter: function() { if (this.timer) window.clearTimeout(this.timer) } });