• 회원가입
  • 로그인
  • 구글아이디로 로그인

[Effect] JQ - stop() 메서드 ★ - 멈추게 하기 (= 슬라이드/애니 중단 = 움직임 멈추기/멈춤 = stop메서드 = 스탑메서드 = 스톱메서드)

목차
  1. stop() 구문
  2. stop() 예제1 - 옵션값 없는 경우
  3. stop() 예제2 - 옵션값 있는 경우
  4. stop(true,true) vs finish() 차이
 

stop() 구문

 

$(selector).stop(stopAll,goToEnd)

 


[매개변수]

 

stopAll

선택. 대기 중 애니메이션 중지할지 여부 지정. (참거짓)

  • false :  모두 멈춤 X. (= 현재 실행 중 메서드만 멈춤.) (기본값)
  • true :  모두 멈춤 O. (=  모든 메서드 다 멈춤.)

 

goToEnd

선택. 현재 실행 중 애니메이션 완료 여부 지정. (참거짓)

  • false :  완료 X. (= 바로 멈춤). (기본값)
  • true :  완료 O. (= 실행 중인 건 끝마침.)

 


 

※ 참고
두 옵션의 기본값이 모두 false 이므로, 
옵션을 따로 적지 않으면 현재의 움직임만 멈추고, 다른 움직임은 계속 작동 함.


※ 주의
true, false 값은 따옴표 없이 입력.

 

stop() 예제1 - 옵션값 없는 경우


<script src="https://ajax.googleapis.com/ajax/libs/jquery/1.12.4/jquery.min.js"></script>
 
<script>
$(document).ready(function(){
    $("#src").click(function(){ 
        $("#url").slideDown(5000);
    });
    $("#stop").click(function(){
        $("#url").stop();
    });
});
</script>
 
<style>
#src, #url {
    width:300px;
    padding: 5px 0;
    font-size: 18px;
    text-align: center;
    background-color: #fd84be;
    color: white;
    border: 1px solid red;
    border-radius: 3px;
}

#url {
    padding: 50px 0;
    border-top:none;
    display: none;
}
</style>

<button id="stop">잠깐 멈추시지!</button>

<div id="src">홈짱닷컴 주소 보기</div>
<div id="url">Homzzang.com</div>

결과보기
※ 「홈짱닷컴 주소보기」부분 클릭 후, 상단 「잠깐 멈추시지!」버튼 클릭.
 

stop() 예제2 - 옵션값 있는 경우


<script src="https://ajax.googleapis.com/ajax/libs/jquery/1.12.4/jquery.min.js"></script>
 
<script>
$(document).ready(function(){
    $("#start").click(function(){
        $("div").animate({height: 200, lineHeight: 200}, 3000); 
        $("div").animate({width: 500}, 3000); 
    });
    $("#stop").click(function(){ 
        $("div").stop(false, false); 
    });
});
</script>

<style>
div {
    margin-top:20px; 
    background:#fd86bf;
    width:300px;
    height:100px;
    line-height:100px;
    text-align:center;
    position:absolute;
}
</style>
 
<p>
<button id="start">움직여라!</button>
<button id="stop">멈춰보시지!</button>
</p>

<div>홈짱닷컴 Homzzang.com</div>

결과보기
※ false, false를 각각 true로도 변경해  어떤 식으로 변하는지 테스트 권장.
 

stop(true,true) vs finish() 차이

 

stop(true,true)

모든 animation 중지. / 현재 실행 중 animation은 끝까지 완료. (= 즉, 이미 실행된 animation까지만 완료.)

 

finish()

queue의 모든 animation을 바로 완료시킴.

 


[stop(true,true) 예제]

 

<script src="https://ajax.googleapis.com/ajax/libs/jquery/3.5.1/jquery.min.js"></script>

<script> 

$(document).ready(function(){

  $("#start").click(function(){

    $("div").animate({height: 200}, 2000);

    $("div").animate({width: 200}, 2000);

    $("div").css("background-color", "red");

  });

  $("#complete").click(function(){

    $("div").stop(true,true);

  });

});

</script> 


<button id="start">Start</button>

<button id="complete">Stop</button><br /><br />

<div style="background:pink;height:100px;width:100px"></div>

 

결과보기


[finish() 예제]

 

<script src="https://ajax.googleapis.com/ajax/libs/jquery/3.5.1/jquery.min.js"></script>

<script> 

$(document).ready(function(){

  $("#start").click(function(){

    $("div").animate({height: 200}, 2000);

    $("div").animate({width: 200}, 2000);

    $("div").css("background-color", "red");

  });

  $("#complete").click(function(){

    $("div").finish();

  });

});

</script> 


<button id="start">Start</button>

<button id="complete">Stop</button><br /><br />

<div style="background:pink;height:100px;width:100px"></div>

 

 결과보기

 


분류 제목
Examples JQ - Quiz - 제이쿼리 퀴즈테스트
Selector JQ - * 선택자 - 모든 요소 선택. (= 전체선택자 = 전체 요소선택자 = 아스테리크 선택자)
Selector JQ - #id 선택자 - 지정 아이디 갖는 요소 선택. (= 아이디 선택자)
Selector JQ - .class 선택자 - 지정 클래스 갖는 요소 선택. (= 클래스 선택자)
Selector JQ - element 선택자 - 지정 요소 모두 선택. (= 요소선택자)
Selector JQ - e1,e2,e3... 선택자 - 여러 요소 선택. (= 여러 요소선택자)
Selector JQ - :first 가상선택자 - 가장 첫번째 지정요소 선택. (= 맨 처음 요소 선택 = 퍼스트 선택자)
Selector JQ - :last 가상선택자 - 가장 마지막 지정 요소 선택. (= 맨뒤 요소 선택 = 라스트 선택자)
Selector JQ - :even 가상선택자 - 짝수 번째 요소 선택. (= 이븐 선텍자)
Selector JQ - :odd 가상선택자 - 홀수 번째 요소 선택. (= 아드 선택자)
Selector JQ - :first-child 가상선택자 - 첫번째 자식요소 선택. (= 퍼스트 차일드 선택자)
Selector JQ - :first-of-type 가상선택자 - 타입 고려 첫번째 자식요소 선택. (= :first-of-…
Selector JQ - :last-child 가상선택자 - 마지막 자식요소 선택. (= 라스트 차일드 선택자)
Selector JQ - :last-of-type 가상선택자 - 타입 고려 마지막 자식요소 선택. (= 라스트 어브 타입 선…
Selector JQ - :nth-child(n) 가상선택자 - 타입 무관 n번째 자식요소 모두 선택. (= nth-chil…
Selector JQ - :nth-last-child(n) 가상선택자 - 타입 무관 마지막 n번째 자식요소 모두 선택. (=…
Selector JQ - :nth-of-type(n) 가상선택자 - 타입 고려 n번째 자식요소 모두 선택. (= 엔스 오브 …
Selector JQ - :nth-last-of-type(n) 가상선택자 - 타입 고려 마지막 N번째 자식요소 선택. (= …
Selector JQ - :only-child 가상선택자 - 그 부모의 타입 무관 유일 자식요소 모두 선택. (= 온리 차일…
Selector JQ - :only-of-type 가상선택자 - 그 부모의 타입 고려 유일 자식요소 모두 선택. (= 온리 …
3/15
목록
찾아주셔서 감사합니다. Since 2012