LoginSignup
1
0

More than 3 years have passed since last update.

モーダルで画像の拡大表示

Last updated at Posted at 2021-04-13

デイトラWeb制作コース中級編DAY6の学び

【この記事に書いてあること】

 【制作物】

 【学び】

【HTML】

index.html
<main class="course-wrapper">
        <div class="course-item">
            <img src="./img/web_first.png" alt="デイトラ初級コース">
                <p>HTML / CSS / Bootstrap</p>
        </div>
        <div class="course-item">
            <img src="./img/web_second.png" alt="デイトラ中級コース">
                <p>HTML / CSS / JavaScript / jQuery</p>
        </div>
        <div class="course-item">
            <img src="./img/web_third.png" alt="デイトラ上級コース">
                <p>PHP / WordPress</p>                    
        </div>
</main>
     <div id="graydisplay"></div>

【CSS】

style.css

#graydisplay {
    display: none;
    position: fixed;
    top: 0;
    left: 0;
    width: 100%;
    max-width: 100%!important;
    height: 100%;
    background: rgba(0,0,0,0.45);
}
#graydisplay img {
    position: absolute;
    top: 0;
    bottom: 0;
    left: 0;
    right: 0;
    margin: auto;
    max-width: 60%;
    max-height: 60%;
    height: 60%;
}

【JavaScript】

maiin.js

$(function () {
    $("main img").click(function () {
        $("#graydisplay").html($(this).prop('outerHTML'));
        $("#graydisplay").fadeIn(200);
    });
    $("#graydisplay, #graydisplay img").click(function () {
        $("#graydisplay").fadeOut(200);
    });
});

1
0
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
1
0