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

[js] JS - JavaScript로 (SlideUp/SlideDown) (FadeOut/FadeIn) 토글 버튼 구현 ※ 순수 자바스크립트로 (슬라이드업/슬라이드다운) (페이드아웃/페이드인) toggle button

(SlideUp/SlideDown) (FadeOut/FadeIn) 토글 버튼 

 

<style>

#hz {

  width: 200px;

  height: 100px;

  background-color: #3498db;

  color: white;

  text-align: center;

  display: block;

}

</style>


<div id="hz">홈짱닷컴 Homzzang.com</div>


<button id="toggleSlideButton">Toggle Slide</button>

<button id="toggleFadeButton">Toggle Fade</button>


<script>

document.addEventListener("DOMContentLoaded", function() {

    const hz = document.querySelector("#hz");

    const toggleSlideButton = document.getElementById("toggleSlideButton");

    const toggleFadeButton = document.getElementById("toggleFadeButton");


    let isSlideVisible = true;

    let isFadeVisible = true;


    toggleSlideButton.addEventListener("click", function() {

        hz.style.transition = "height 0.5s ease";

        if (isSlideVisible) {

           hz.style.height = "0";

        } else {

           hz.style.height = "100px";

        }

        isSlideVisible = !isSlideVisible;

    });


    toggleFadeButton.addEventListener("click", function() {

         hz.style.transition = "opacity 0.5s ease";

         if (isFadeVisible) {

            hz.style.opacity = "0";

         } else {

            hz.style.opacity = "1";

        }

        isFadeVisible = !isFadeVisible;

    });

});

</script>


결과보기


방문 감사합니다. (즐겨찾기 등록: Ctrl + D)

분류 제목
js JS - with 키워드 - 객체 이용해 구문작성 (= with키워드 = 위드키워드)
js JS - 입력한 패스워드 확인 (보이기/숨기기) 토글 버튼 넣기
js JS - JavaScript로 (SlideUp/SlideDown) (FadeOut/FadeIn) 토글 버튼 …
js JS - 이미지 위에 마우스허버 시 툴팁창(Tooltip) 띄우기 ※ 클래스 속성값과 동일한 타이틀 속성 생…
js JS - 모든 링크 주소를 특정 URL주소로 일괄 변경
js JS - 화면 리사이즈 시, 스크롤바 가운데로 이동 (= 화면크기 변경 시, 스크롤바 중앙에 위치시키기)
4/4
목록
찾아주셔서 감사합니다. Since 2012