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

[image] CSS - Image Modal - (Advanced) - (이미지 모달 띄우기 효과)

이미지 모달 효과

 

<style>

#basicImg {

  border-radius: 5px;

  cursor: pointer;

  transition: 0.3s;

  width:100%;

  max-width:300px

}


#basicImg:hover {opacity: 0.7;}


/* 모달 (배경) */

.modalBox {

  display: none;

  position: fixed;

  z-index: 1;

  padding-top: 100px;

  left: 0;

  top: 0;

  width: 100%;

  height: 100%;

  overflow: auto;

  background-color: rgb(0,0,0); /* 예비색 */

  background-color: rgba(0,0,0,0.9); /* 기본색 */

}


/* 모달 내용(이미지) */

.modalImg {

  margin: auto;

  display: block;

  width: 80%;

  max-width: 700px;

}


/* 모달 이미지의 캡션 */

#caption {

  margin: auto;

  display: block;

  width: 80%;

  max-width: 700px;

  text-align: center;

  color: #ccc;

  padding: 10px 0;

  height: 150px;

}


/* 애니메이션 효과 */

.modalImg, #caption {  

  -webkit-animation-name: zoom;

  -webkit-animation-duration: 0.6s;

  animation-name: zoom;

  animation-duration: 0.6s;

}


@-webkit-keyframes zoom {

  from {-webkit-transform:scale(0)} 

  to {-webkit-transform:scale(1)}

}


@keyframes zoom {

  from {transform:scale(0)} 

  to {transform:scale(1)}

}


/* 모달 닫기 버튼 */

.closeBtn {

  position: absolute;

  top: 15px;

  right: 35px;

  color: #f1f1f1;

  font-size: 40px;

  font-weight: bold;

  transition: 0.3s;

}


.closeBtn:hover,

.closeBtn:focus {

  color: #bbb;

  text-decoration: none;

  cursor: pointer;

}


/* 작은 기기 경우, 이미지 너비 100% 설정 */

@media only screen and (max-width: 700px){

  .modalImg {

    width: 100%;

  }

}

</style>


<img id="basicImg" src="https://source.unsplash.com/random" alt="랜덤이미지">


<!-- 모달 박스 -->

<div id="modalBox" class="modalBox">

  <span class="closeBtn">&times;</span>

  <img class="modalImg" id="modalImg">

  <div id="caption"></div>

</div>


<script>

// 요소 얻기

var modalBox = document.getElementById("modalBox");

var basicImg = document.getElementById("basicImg");

var modalImg = document.getElementById("modalImg");

var caption = document.getElementById("caption");


// 이미지를 모달에 넣기 (alt 텍스트를 캡션으로 사용)

basicImg.onclick = function(){

  modalBox.style.display = "block";

  modalImg.src = this.src;

  caption.innerHTML = this.alt;

}


// 모달 닫기 버튼

var closeBtn = document.getElementsByClassName("closeBtn")[0];


// 모달 닫기 버튼 클릭 시, 모달 닫기

closeBtn.onclick = function() { 

  modalBox.style.display = "none";

}


// 모달 클릭 시, 모달 닫기

modalBox.onclick = function() { 

  modalBox.style.display = "none";

}

</script>

 

결과보기

PS. 모달 (Modal) : 이목 집중 위한 팝업처럼 띄우는 화면전환 효과

 


분류 제목
func CSS - rgb() 함수 - (빨강,녹색,파랑)으로 색상 정의. (= rgb함수 = 알지비함수)
func CSS - rgba() 함수 ★ - (빨강,녹색,파랑,불투명도)으로 색상 정의. (= rgba함수 = 알지비…
func CSS - var() 함수 ★★ - 사용자정의 속성/속성값 변수 호출 (= var함수 = 바함수) ※ :r…
css CSS - 선택자 명시도 계산 - (CSS 적용 선택자우선순위 판별 = CSS적용순서 체크)
css CSS - 폰트오썸 아이콘 배경이미지 적용 + fontawesome 엑박원인 엑박해결
css CSS - 부모요소 안 자식요소 너비를 부모요소 밖으로 화면너비 100% 채우기. (= 부모이탈자식너비전체설…
css CSS - (블럭요소 + 인라인요소:이미지/텍스트) 중앙정렬/가운데정렬 원리/방법
selector CSS - :not(selector) 선택자 - (특정요소/특정선택자) 아닌 모든요소선택 (= not선택자 …
selector CSS - :checked 가상선택자 - 체크된요소선택 (= :checked선택자 = 체크트 선택자) ※ 자…
selector CSS - :disabled 가상선택자 - 비활성화 된 요소 선택 (= 실행불능요소 = 작동불능요소 = :d…
selector CSS - :empty 가상선택자 - 자식/내용 없는 텅 빈 요소 선택 (= :empty선택자 = 엠프티 선…
selector CSS - :enabled 가상선택자 - 활성화 된 요소 선택 (= 작동가능요소 = 실행가능요소 = :ena…
selector CSS - :first-of-type 가상선택자 - 지정타입 첫번째자식요소 (순서선택자/순번선택자/타입선택자…
selector CSS - :in-range 가상선택자 - 지정범위안값 갖는 요소 선택 (= 인레인지선택자 IE13)
selector CSS - :invalid 가상선택자 - 유효하지 않는 값 요소 (= :invalid선택자 = 인밸리드 선택…
selector CSS - :last-child 가상선택자 - 그 부모의 마지막자식요소인 지정요소 (= :last-child…
selector CSS - :last-of-type 가상선택자 - 지정타입 마지막자식요소 (순서선택자,타입선택자, IE9)
selector CSS - :nth-child(n) 가상선택자 ★ - 그 부모의 n번째 자식요소 (=nth-child선택자 …
selector CSS - :nth-last-child(n) 가상선택자 ★★★ - (그 부모의) 마지막n번째 자식요소 (= …
selector CSS - :nth-last-of-type(n) 가상선택자 - 타입마지막n번째 자식요소 (순서선택자,,타입…
13/25
목록
찾아주셔서 감사합니다. Since 2012