테스트 사이트 - 개발 중인 베타 버전입니다

이미지 모달 (고급)

· 8년 전 · 2489

이미지 모달 (고급)

이 예제는 CSS와 JavaScript가 함께 작동하는 방법을 보여줍니다.


먼저 CSS를 사용하여 모달 창 (대화 상자)을 만들고 기본적으로 숨 깁니다.


그런 다음 JavaScript를 사용하여 모달 창을 표시하고 사용자가 이미지를 클릭하면 모달 안에 이미지가 표시됩니다.


노던 라이트, 노르웨이

// Get the modal

var modal = document.getElementById('myModal');


// Get the image and insert it inside the modal - use its "alt" text as a caption

var img = document.getElementById('myImg');

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

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

img.onclick = function(){

    modal.style.display = "block";

    modalImg.src = this.src;

    captionText.innerHTML = this.alt;

}


// Get the <span> element that closes the modal

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


// When the user clicks on <span> (x), close the modal

span.onclick = function() { 

    modal.style.display = "none";

}

댓글 작성

댓글을 작성하시려면 로그인이 필요합니다.

로그인하기

게시글 목록

번호 제목
3381
3380
3379
3378
3377
3376
3375
3374
3373
3372
3371
3370
3369
3368
3367
3366
3365
3364
3363
3362
3361
3360
3359
3358
3357
3356
3355
3354
3351
3350