【问题标题】:Jquery: On mouseenter and mouseleave completeJquery:在 mouseenter 和 mouseleave 完成
【发布时间】:2015-09-24 09:10:45
【问题描述】:

有没有办法在鼠标事件上创建完整的事件回调?例如:

var process=function(event){//process event};
var complete=function(event){//on event complete,ends};

$('div').on('mouseenter',process,complete);

感谢您的帮助

【问题讨论】:

  • 为什么你不能只注册 mouseenter 和 mouseleave 处理程序 - $('div').mouseenter(process).mouseleave(complete);
  • 或使用$('div').hover(process,complete);
  • @ArunPJohny 正如我在 Jquery 文档中看到的那样,悬停是 $('div').hover( handlerIn, handlerOut ) - api.jquery.com/hover 从你上次编辑中我需要类似: $('div' ).mouseenter(进程,完成).mouseleave(进程,完成);在每个事件中,我都需要知道它什么时候结束……有可能吗?
  • 那么完整是什么意思
  • 您所要求的是.hover() 所做的。 api.jquery.com/hover$('div').on('hover',process,complete);

标签: jquery mouseevent mouseenter mouseleave


【解决方案1】:

您可以使用.mouseenter().mouseout() 事件尝试这样的事情:

$(function(){
  $( ".overout" )
    .mouseout(function() {
      $( "p:first", this ).text( "mouse out" );
    })
    .mouseover(function() {
      $( "p:first", this ).text( "mouse over" );
  });
});
<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script>
<div class="overout">
  <p style="background:#ff0; font-size:29px;">move your mouse</p>
</div>

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2023-03-14
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2013-03-05
    相关资源
    最近更新 更多