카테고리 없음

[jquery] 이 jquery 함수에 일시 중지를 추가하려면 어떻게해야합니까?

행복을전해요 2021. 2. 23. 12:55

Use jQuery's hover

$( selector ).hover( handlerIn, handlerOut )

Short for

$( selector ).mouseenter( handlerIn ).mouseleave( handlerOut );
-------------------

에 대한 참조를 저장해야합니다 setinterval(). 마우스를 올리면 간격이 지워져 슬라이드 쇼가 중지됩니다. 아래 예에서는 마우스 오버시 다시 시작할 자유를 얻었습니다. 더 쉽게 할 수 있지만 이것이 더 잘 설명됩니다.

var slideshow;
$(document).ready(function(){
    slideshow = setInterval( swapImages, 5000);
    
    
        $('#myGallery')
                .mouseover(function(){ clearInterval( slideshow ) })
                        .mouseout(function(){ slideshow = setInterval( swapImages, 5000); });
                        });
                        
-------------------

나는 당신이 다음과 같은 것을 요구하고 있다고 생각 합니다.

$('#hello').mouseout(function() {
    /*script to execute*/
    });
    

데모



출처
https://stackoverflow.com/questions/22080042