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

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

 

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

분류 제목
button CSS - Button - 버튼스타일 (버튼크기, 버튼색깔, 버튼비활성화, 버튼그룹, 이미지위버튼)
position CSS - overflow 속성 ★★ - 범위이탈요소처리 (= 범위넘는요소처리 = 스크롤바 생성 = over…
font CSS - font-family 속성 ★ - 글자종류 (= font-family속성 = 폰트패밀리속성 = 글…
position CSS - position 속성 ★★★ - 위치기준대상지정 (= 위치속성 = 포지션속성 = 위치조정 = po…
selector CSS - :focus 선택자 - 포커스 된 요소 선택 (= :focus선택자 = 포커스선택자) (IE8…
intro CSS - 스타일 적용 방법 3가지 ★★★ - (인라인스타일 / 내부스타일 / 외부스타일) CSS적용순서 +…
font CSS - font-style 속성 - 글자기울기 (= 이텔릭체 여부 = 이탤릭 글씨체 = 글자 기울려쓰기 … 1
font CSS - font-size 속성 ★ - 글자크기 (= 글씨체크기= 글씨크기 = 서체크기= 글씨크기 = …
selector CSS - ID선택자, class선택자 + CSS우선순위 ★★★ (= 아이디선택자, 클래스선택자, CSS명시…
selector CSS - :not(selector) 선택자 - (특정요소/특정선택자) 아닌 모든요소선택 (= not선택자 …
selector CSS - :first-child 가상선택자 - 그부모요소의 첫번째자식요소 (= 퍼스트차일드선택자, IE7)
table CSS - border-collapse 속성★ - 테두리겹침설정 (= 테두리중첩설정 = 테두리이중방지 = b…
position CSS - float 속성 ★★★ - 요소나란히 (= 요소한줄로 = 요소가로로 = 요소옆으로 = float속…
text CSS - color 속성 ★ - 글자색깔 (=글자색상=글자색깔=글자컬러 = 텍스트색깔 = 컬러속성 = co…
1/25
목록
찾아주셔서 감사합니다. Since 2012