2013-08-02 4 views
0

는 내가 예 - 작업mouseout이 맞는지 여부를 감지하는 방법은 무엇입니까?

Jsfiddle

나는 div 섹션로 마우스 이벤트를 감지하려고으로이 간단한 바이올린있다. 이 이미지에 마우스를 올리면 캡션이 표시됩니다. "Change Image"라고 말합니다. 5 초 후 캡션이 사라집니다.

setInterval을 사용하고 있습니다. 이제이 이미지의 마우스 아웃을하면 Interval 함수를 호출해야합니다.

jQuery에서 mouseout 이벤트를 어떻게 감지합니까?

점프는 - 시도

$(function() { 
     $('.image-profile').mouseover(function() { 
      $('.change-image').stop().show(); 

      if ($('.image-profile').mouseout()== true) { 
       TimeOut(); 
      } 
     }); 

     setInterval(function TimeOut() { 
      $('.change-image').fadeOut() 
     }, 5000 

     ); 
    }); 
+3

는'mouseover', 왜'어떤 다른 일을 mouseout' 것인가? – Yoshi

+2

+'setInterval()'을 사용하고 싶지는 않을 것입니다. 대신'setTimeout()'을 시도하십시오. – Teemu

+0

@ Yoshi, 그냥 mouseout 이벤트를 감지하기 때문에, 그것을 사용하는 또 다른 방법입니다. – Manoj

답변

0
$('.image-profile').on('mouseleave', function() { 
    setTimeout(function() { 
     $('.change-image').fadeOut() 
    }, 5000); 
}); 
1
var ImageProfileTimer; 

$('.image-profile').on('mouseenter',function(){ 
    clearTimeout(ImageProfileTimer); 
    $('.change-image').stop().show(); 
}).on('mouseleave',function(){ 
    ImageProfileTimer = setTimeout(function(){ 
     $('.change-image').fadeOut() 
    }, 5000); 
}); 

사용의 setTimeout 및 사항 clearTimeout

데모 : http://jsfiddle.net/xMNTB/9/

+0

mouseleave의 다른 기능을 사용하지 않고 수행 할 수 있습니까? 내가 mouseout 사실인지 감지 싶어요. – Manoj

+0

네, 할 수 있어요 @Manoz mouseleave를 mouseout으로 변경하십시오 – l2aelba

+0

+ http://stackoverflow.com/questions/4258615/what-is-the-difference-between-jquerys-mouseout-and-mouseleave – l2aelba

0

http://jsfiddle.net/xMNTB/7/

이제 마우스에서 div 표시가 나타나고 마우스를 끈 후 5 초 후에 사라집니다.

$(function() { 

    $('.image-profile').mouseenter(function() { 
     $('.change-image').stop().show(); 
    }); 

    $('.image-profile').mouseleave(function() { 
     setTimeout(function TimeOut() { 
      $('.change-image').fadeOut() 
     }, 5000); 
    }); 

}); 
0

이 시도 :

이미 사용
(function() { 
    $('.image-profile').mouseover(function() { 
     $('.change-image').stop().show(); 

     if ($('.image-profile').mouseout() == true) { 
      TimeOut(); 
     } 
    }).mouseout(function() { 
     setInterval(function TimeOut() { 
      $('.change-image').fadeOut() 
     }, 5000); 
    }); 
}); 

JSFIDDLE DEMO

관련 문제