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

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

 


분류 제목
flex CSS - align-content 속성(C) ★★ - 줄바꿈 된 경우, 교차축 기준으로 라인 정렬. (= …
text CSS - word-spacing 속성 ★ - 텍스트 단어간 간격 (= 단어간격 = word-spacing…
border CSS - border-image-slice 속성 - 테두리이미지자르기 (IE11)
css CSS - 스크롤 따라다니는 양사이드배너 (= 양쪽날개배너 = 사이드고정배너) 3단 레이아웃
font CSS - font-variant 속성 - 작은 대문자 (= font-variant속성 = 폰트베리언트 = …
func CSS - cubic-bezier() 함수 - 이동 속도 변화 (= 입방체 베지에곡선 =cubic-bezie…
css CSS - 폰트오썸 아이콘 배경이미지 적용 + fontawesome 엑박원인 엑박해결
selector CSS - ::first-letter 가상선택자 - 요소의 첫번째글자 선택 (= ::first-letter선…
selector CSS - element 요소선택자 ★ - 지정 요소 선택. (요소선택자군)
selector CSS - ::-webkit-scrollbar - 스크롤바 선택자 (= 스크롤바 모양 디자인 커스텀 = Cu…
selector CSS - :target 가상선택자 - 내부링크목적지요소 (= :target선택자 = 타겟선택자 = 목적지선…
list CSS - list-style-image 속성 - 리스트 스타일 이미지 (= 리스트 마커 이미지 = list…
intro CSS - 발전사 (CSS1 → CSS2.01 → CSS) + 제작관리 단체
transition CSS - transition 속성 ★★★ - 지정시간 동안 천천히 변화 (= transition속성 = 트…
pagination CSS - 페이징 - 마우스오버 시 색깔 변경 (Active and Hoverable Pagination)
selector CSS - :valid 가상선택자 - 유효요소 (= 유효값 갖는 요소 선택, IE10)
selector CSS - :invalid 가상선택자 - 유효하지 않는 값 요소 (= :invalid선택자 = 인밸리드 선택…
text CSS - text-fill-color 속성 (비표준) - 텍스트글자색 (= 글자전경색 =text-fill-…
outline CSS - outline 속성 ★ - 테두리 외곽선 일괄 지정. (= outline속성 = 아웃라인속성)
css CSS - 인풋태그 높이통일 (= 동일높이 = 높이동일 = 높이같게 = 세로길이 똑같게 = 높이맞추기) IN…
19/27
목록
찾아주셔서 감사합니다. Since 2012