[jQuery] 이미지 슬라이드쇼 (화면 전환)


제이쿼리를 이용해 이미지 슬라이드쇼 만들기 - 화면 전환 방식



See the Pen 이미지 슬라이드쇼2 by Jinsol (@losuif) on CodePen.



HTML

<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Slide Show</title>
    <link rel="stylesheet" href="style/style.css">
</head>
<body>
    <div id="wrap">
        <h1>슬라이드쇼 : 화면전환방식</h1>

        <div id="slideShow">
            <!-- 이미지 한개의 크기 (780*350) -->

            <div id="shuttleFrame" class="flex-container">
                <!-- >= 이미지 전체 개수의 폭 -->

                <a href="#">
                    <img src="https://images.unsplash.com/photo-1593642533144-3d62aa4783ec?ixid=MnwxMjA3fDF8MHxlZGl0b3JpYWwtZmVlZHwxNnx8fGVufDB8fHx8&ixlib=rb-1.2.1&auto=format&fit=crop&w=500&q=60" alt="이미지1" width="780px" height="350px">
                     <span>abcde</span>
                </a>
                <a href="#">
                    <img src="https://images.unsplash.com/photo-1633684268648-c6360f92a08d?ixid=MnwxMjA3fDB8MHxlZGl0b3JpYWwtZmVlZHwxOHx8fGVufDB8fHx8&ixlib=rb-1.2.1&auto=format&fit=crop&w=500&q=60" alt="이미지2" width="780px" height="350px">
                    <span>abcde
                    </span>
                </a>
                <a href="#">
                    <img src="https://images.unsplash.com/photo-1593642702909-dec73df255d7?ixid=MnwxMjA3fDF8MHxlZGl0b3JpYWwtZmVlZHw0MHx8fGVufDB8fHx8&ixlib=rb-1.2.1&auto=format&fit=crop&w=500&q=60" alt="이미지3" width="780px" height="350px">
                    <span>abcde</span>
                </a>
            </div>
            <!-- div#shuttleFrame -->
        </div>
        <!-- div#slideShow -->

    </div>
    <!-- div#wrap -->


    <script src="lib/jquery-3.6.0.min.js"></script>
    <script src="script/script.js"></script>
</body>
</html>



Reset CSS

@charset "UTF-8";
@import url('https://fonts.googleapis.com/css2?family=Nanum+Gothic&display=swap');


/*///////////////////////// CSS 리셋 파일 /////////////////////////*/

* {
    color: #222;   
    font-family: "Nanum Gothic", sans-serif;  
    text-decoration: none; 
    padding: 0;
    margin: 0;
    box-sizing: border-box;    
}

a:link {
    color: #333;
} 
a:visited {    
    color: #333;
} 
a:hover {
    color: #444;
} 
a:active {
    color: #444;
} 

img {
    vertical-align: middle;
}

ul {
    list-style: none;
}

.flex-container {
    display: flex;
}



CSS

@charset "UTF-8";
@import url(../style/style_Reset.css);

div#wrap {
    width: 900px;
    padding: 30px;
    border: 1px solid #000;
    margin: 20px auto;
    text-align: center;
}

#slideShow {
    width: 780px;
    height: 350px;
    margin: 0 auto;
    padding: 5px;
    /* overflow: hidden; */
}

#shuttleFrame {
    position: relative;
}

#slideShow #shuttleFrame a{
    position: absolute;
}

#slideShow #shuttleFrame a:not(:first-child){
    display: none;
}
#slideShow #shuttleFrame span {

    width: 460px;
    text-align: center;
    margin: 0 auto;
    font-size: 24px;
    font-weight: bold;
    color: #fff;
    padding: 10px 30px;
    border: 10px solid rgba(240, 248, 255, 0.6);
    border-radius: 10px;
    background-color: rgba(148, 159, 169, 0.6);
    position: absolute;
    top: 50%;
    left: 50%;
    transform: translate(-50%, -50%);
}



JavaScript

setInterval(fnSilde, 3000);

function fnSilde(){

    $("#shuttleFrame a:first-child").fadeOut(
        800,
        function(){
            $("#shuttleFrame a:first-child").insertAfter("#shuttleFrame a:last-child");
        });
    $("#shuttleFrame a:nth-child(2)").fadeIn(1000);

};

Categories:

Javascript   jQuery