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

[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) : 이목 집중 위한 팝업처럼 띄우는 화면전환 효과

 


분류 제목
gradient CSS - repeating-radial-gradient () 함수 - 방사형 그레이디언트 반복 (= 그라디…
selector CSS - :read-write 가상선택자 - 읽고쓰기가능요소 (= readonly속성없는요소, IE13)
border CSS - border-image-outset 속성 - 테두리 경계 넘는 이미지 양. (= 보더이미지아웃셋속…
selector CSS - :optional 가상선택자 - 선택입력요소 (= required 속성없는 요소, IE10)
css CSS - 구글 로그인 포커스 애니 효과 (Google Logn Foucs Animation Effect) …
responsive CSS - RES Intro - (반응형 웹디자인 소개)
pagination CSS - 페이징 - 둥근테두리 효과 (Rounded bordered pagination)
image CSS - Thumbnail Images - (썸네일 이미지 스타일)
selector CSS - .class1 .class2 클래스선택자 ★★ - class1자손 중 class2 갖는 모든 요소
pagination CSS - 페이징 - 트랜지션 효과 (Hoverable Transition Effect)
gradient CSS - repeating-linear-gradient () 함수 - 반복 선형 그레이디언트 ※ 패턴 배경
border CSS - border-image-source 속성 - 테두리 이미지 주소 (= border-image-so…
image CSS - object-fit 속성 - 컨테이너에 맞게 '이미지/비디오' 크기 조정 방법 지정 (= obje…
border CSS - border-right 속성 - 테두리우측일괄 (= 테두리오른쪽일괄 = border-right속성…
pagination CSS - 페이징 - 가운데 정렬 (Centered Pagination)
animation CSS - animation-timing-function 속성 - 애니재생중속도변화 (= 움직임 중 속도변경…
border CSS - border-left-style 속성 - 테두리좌측모양 (= 테두리왼쪽모양 = border-lef…
border CSS - border-image-width 속성 - 테두리 이미지 너비 (= border-image-wid…
border CSS - border-right-color 속성 - 테두리우측색상 (= 테두리오른쪽색상 = 테두리우측색깔…
border CSS - border-top-style 속성 - 테두리상단모양 (= 테두리상단스타일 = border-top…
14/27
목록
찾아주셔서 감사합니다. Since 2012