얼렁뚱땅코드/jquery

가로세로 슬라이드

얼렁뚱땅 디자이너 2019. 10. 29. 22:14
<!DOCTYPE html>
<html lang="en">

<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <meta http-equiv="X-UA-Compatible" content="ie=edge">
    <title>Document</title>
    <link rel="stylesheet" href="css/reset.css">
</head>

<link rel="stylesheet" href="/reset.css">
<style>
    .bgcontainer{width:100%; height:100vh; position: fixed; border: 1px solid #000; margin:auto;}
    .bgcontainer::before{position: absolute; width: 100%; height: 100%; background:rgba(0, 0, 0, 0.5); z-index: 500; content: "";}
    .bgwrap{width:300%; height:100%; display: flex; margin-left: -100%;}
    .bg{width: 33.3333%;height: 100%; background-position: center; filter: blur(3px);}
    .bg01{background: url('img/bg01.webp') no-repeat; background-size:cover;}
    .bg02{background: url('img/bg02.webp') no-repeat; background-size:cover;}
    .bg03{background: url('img/bg03.jpg') no-repeat; background-size:cover;}

    .videocontainer{width:560px; height:315px; position: absolute; top: 50%; transform: translateY(-50%); left: 50%; margin-left: -560px; margin-top:-35px;}
    .videowrap{width: 100%; height: 100%; overflow:hidden;}
    .video{width: 100%; height: 100%;}
    iframe{width: 560px; height:315px;}

    .btn{position: absolute; top:50%; transform: translateY(-50%); z-index: 999;}
    a.prev{left: 0;}
    a.next{right: 0;}

</style>
<script src="https://ajax.googleapis.com/ajax/libs/jquery/3.4.1/jquery.min.js"></script>
<script>
    $(function(){
        var w = $('.bg').width()
        var h = $('.video').height()
        
        $('a.prev').click(function(){
            $('.bgwrap').animate({'margin-left':'0'},1000,function(){
                $('.bg').last().prependTo('.bgwrap')
                $('.bgwrap').css({'margin-left':-w})
            })

            $('.videowrap').animate({'margin-top':'0'},1000,function(){
                $('.video').last().prependTo('.videowrap')
                $('.videowrap').css({'margin-top':-h})
            })
        })
        $('a.next').click(function(){
            $('.bgwrap').animate({'margin-left':-w*2},1000,function(){
                $('.bg').first().appendTo('.bgwrap')
                $('.bgwrap').css({'margin-left':-w})
            })

            $('.videowrap').animate({'margin-top':-h*2},1000,function(){
                $('.video').first().appendTo('.videowrap')
                $('.videowrap').css({'margin-top':-h})
            })
        })          
    })
</script>
<body>
    <div class="bgcontainer">
        <div class="bgwrap">
            <div class="bg bg01"></div>
            <div class="bg bg02"></div>
            <div class="bg bg03"></div>
        </div>
    </div>

    <div class="videocontainer">
        <div class="videowrap">
            <div class="video"><iframe width="560" height="315" src="https://www.youtube.com/embed/h0q2L1_6JpI" frameborder="0"></iframe></div>
            <div class="video"><iframe width="560" height="315" src="https://www.youtube.com/embed/YUcMkr-YO0U" frameborder="0"></iframe></div>
            <div class="video"><iframe width="560" height="315" src="https://www.youtube.com/embed/p4kQwWf8nvI" frameborder="0"></iframe></div>
        </div>

        <a href="#" class="prev btn"><img src="img/prev.png" alt=""/></a>
        <a href="#" class="next btn"><img src="img/next.png" alt=""/></a>
    </div>

    <div class="textcontainer">
        <div class="textwrap">
            <div class="text"></div>
            <div class="text"></div>
            <div class="text"></div>
        </div>
    </div>
</body>

</html>

 

세로에서 오류발생