【问题标题】:jquery stop function (not animate)jquery 停止功能(非动画)
【发布时间】:2016-09-23 09:03:26
【问题描述】:

论文。胆大。散文

论文。胆大。散文

论文。胆大。散文

论文。胆大。散文

鼠标事件功能:

function stat(){
 $('p').mouseenter(function(){
  $(this).find('b').css({background:'yellow',color:'red'});
  $(this).mouseleave(function(){
   $(this).find('b').css({background:'transparent',color:'black'})
  })
 })
}

windows 调整 jquery 代码大小:

$(window).resize(function(){
 if( $(window).width() < 480 ){
  $('p').find('b').css({background:'red',color:'white'});

  // stopped stat() function !..
 }else{
  $('p').find('b').css({background:'transparent',color:'black'});
  // start stat() function !..
  stat();
 }
})

我需要;停止函数 stat()。 stat()函数在第一次工作时不会停止

JSfiddle

【问题讨论】:

    标签: javascript jquery function events


    【解决方案1】:

    你必须关闭你的事件监听器。

    $(window).resize(function(){
     if( $(window).width() < 480 ){
      $('p').find('b').css({background:'red',color:'white'});
    
      // stopped stat() function !..
      $('p').off('mouseenter').off('mouseleave');
     }else{
      $('p').find('b').css({background:'transparent',color:'black'});
      // start stat() function !..
      stat();
     }
    })
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 2012-10-16
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2015-02-26
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多