jQuery 토글() 메서드

❮ jQuery 효과 메서드

예시

모든 <p> 요소에 대해 숨기기 및 표시 간 전환:

$("button").click(function(){
  $("p").toggle();
});

정의 및 사용

toggle() 메서드 는 선택한 요소에 대해 hide()show() 사이를 토글합니다.

이 메서드는 가시성을 위해 선택한 요소를 확인합니다. 요소가 숨겨져 있으면 show()가 실행됩니다. 요소가 표시되면 hide()가 실행됩니다. - 이것은 토글 효과를 만듭니다.

참고 : 숨겨진 요소는 전혀 표시되지 않습니다(더 이상 페이지 레이아웃에 영향을 미치지 않음).

팁: 이 방법을 사용하여 사용자 정의 기능 간에 전환할 수도 있습니다.


통사론

$(selector).toggle(speed,easing,callback)

Parameter Description
speed Optional. Specifies the speed of the hide/show effect

Possible values:

  • milliseconds
  • "slow"
  • "fast"
easing Optional. Specifies the speed of the element in different points of the animation. Default value is "swing"

Possible values:

  • "swing" - moves slower at the beginning/end, but faster in the middle
  • "linear" - moves in a constant speed
Tip: More easing functions are available in external plugins
callback Optional. A function to be executed after the toggle() method is completed

To learn more about callback, visit our jQuery Callback chapter


직접 해보십시오 - 예


사용 속도 매개변수를 사용하여 숨기기/표시 효과의 속도를 지정하는 방법입니다.


사용 숨기기/표시 효과를 전환할 때 콜백 매개변수를 사용하는 방법입니다.


❮ jQuery 효과 메서드