자바스크립트

웹을 움직이는 언어, 자바스크립트! ES6+, Vue, React, Node.js 등 모던 JS 생태계를 깊이 있게 탐구하는 공간입니다.

2025.02.22 03:00

jQuery .show() 메서드 이해

  • 나우호스팅 21일 전 2025.02.22 03:00
  • 14
    0

jquery .show()


jQuery .show() 메서드


jQuery .show() 메서드는 선택한 요소를 표시합니다. 선택한 요소가 숨겨져 있다면, 이 메서드는 요소를 표시합니다. 숨겨지지 않은 요소는 영향을 받지 않습니다.

자바스크립트 소스 코드


jQuery .show() 메서드는 jQuery의 core 코드에서 다음과 같이 구현되어 있습니다.

#hostingforum.kr
javascript

// jQuery 3.6.0 버전의 core 코드

// jQuery.show()

show: function( speed, easing, callback ) {

  return this.engine.show( speed, easing, callback );

},



이 코드는 jQuery .show() 메서드를 호출할 때 speed, easing, callback 파라미터를 받습니다. 이 메서드는 jQuery.engine.show() 메서드를 호출하여 실제로 요소를 표시합니다.

#hostingforum.kr
javascript

// jQuery 3.6.0 버전의 core 코드

// jQuery.engine.show()

show: function( speed, easing, callback ) {

  var self = this;

  speed = speed || 400;

  easing = easing || "swing";



  if ( this.nodeType === 1 || this.nodeType === 11 || this.nodeType === 9 ) {

    // 요소가 존재하는 경우

    if ( this.style.display === "none" ) {

      // 요소가 숨겨져 있는 경우

      this.style.display = "";

    }



    if ( this.style.visibility === "hidden" ) {

      // 요소가 숨겨져 있는 경우

      this.style.visibility = "";

    }



    if ( this.style.opacity === "0" ) {

      // 요소가 투명한 경우

      this.style.opacity = 1;

    }



    if ( this.style.zoom === "1" ) {

      // 요소가 축소된 경우

      this.style.zoom = 1;

    }



    if ( jQuery.support.opacity && ( this.style.opacity === "" || this.style.opacity === "1" ) ) {

      // 요소가 투명하지 않은 경우

      return;

    }



    if ( jQuery.fx.off ) {

      // 애니메이션을 끄는 경우

      this.style.display = "block";

    } else {

      // 애니메이션을 켜는 경우

      jQuery.fx.step.show = function( fx ) {

        if ( !fx.done ) {

          fx.now = Math.max( 0, Math.min( 1, fx.now || 0 ) );

          fx.elem.style.opacity = fx.now;

          fx.elem.style.zoom = fx.now * 100;

        }

      };



      jQuery.fx( this, speed, easing, callback );

    }

  }

},



이 코드는 jQuery .show() 메서드를 호출할 때 speed, easing, callback 파라미터를 받습니다. 이 메서드는 요소가 존재하는 경우, 요소가 숨겨져 있는 경우, 요소가 투명한 경우, 요소가 축소된 경우에 따라서 다양한 처리를 합니다.

예제


#hostingforum.kr
html

<!DOCTYPE html>

<html>

<head>

  <title>jQuery .show() 메서드 예제</title>

  <script src="https://code.jquery.com/jquery-3.6.0.min.js"></script>

  <style>

    #hide {

      display: none;

    }

  </style>

</head>

<body>

  <button id="show-btn">Show</button>

  <div id="hide">숨겨진 요소</div>



  <script>

    $("#show-btn").click(function() {

      $("#hide").show();

    });

  </script>

</body>

</html>



이 예제는 jQuery .show() 메서드를 사용하여 숨겨진 요소를 표시하는 예제입니다. 버튼을 클릭하면 숨겨진 요소가 표시됩니다.

이 게시물에 포함된 라이브러리

[PHP_CONFIG] engine - PHP 엔진 활성화 여부
[PHP] sin - 사인
[PHP] min - 가장 낮은 값 찾기
[PHP] max - 가장 높은 값 찾기
[PHP] asin - 아크 사인
  • profile_image
    나우호스팅 @pcs8404 

    호스팅포럼 화이팅!

    댓글목록

    등록된 댓글이 없습니다.

  • 자바스크립트 포인트 정책
      글쓰기
      50P
      댓글
      10P
  • 전체 35건 / 1 페이지

검색

게시물 검색