소스자료실

스크롤 클리핑

by 콘디쌤 posted May 31, 2017
?

단축키

Prev이전 문서

Next다음 문서

ESC닫기

크게 작게 위로 아래로 댓글로 가기 인쇄

<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8">
<meta http-equiv="X-UA-Compatible" content="IE=edge,chrome=1">
 
<title></title>
 

<style>
    body {
        margin: 0;
    }
    div, section {
        position: relative;
    }
    section {
        height: 1000px;
        border-bottom: 1px solid red;
    }
    section .desc {
        position: fixed;
        top: 400px;
        left: 100px;
        width: 400px;
        height: 300px;
        font-size: 70px;
        font-weight: bold;
    }
    section:nth-child(1) .desc {
        background-color: rgba(255, 0, 0, 1);
        z-index: 3;
        
        clip: rect( auto, auto, 400px, auto);
    }
    section:nth-child(2) .desc {
        background-color: rgba(0, 255, 0, 1);
        z-index: 2;
    }
    section:nth-child(3) .desc {
        background-color: rgba(0, 0, 255, 1);
        z-index: 1;
    }
    
    .scroll {
        position: fixed;
        top: 0; left: 0;
        font-size: 30px;
    }
</style>
    
     
<script src="https://ajax.googleapis.com/ajax/libs/jquery/3.1.1/jquery.min.js"></script>
<script>

$(document).ready(function(){
   
    $(window).scroll(function(){
        
        var scrollTop = $(window).scrollTop();
        var loc = 200;
        var loc2 = 1200;
        
        $(".scroll").text(scrollTop);
        
        if (scrollTop > loc ) {
            $("section").eq(0).find(".desc").css("clip", "rect( auto, auto, "+ (loc + 400  - scrollTop) +"px, auto)");
        }
        
        if (scrollTop > loc2 ) {
            $("section").eq(1).find(".desc").css("clip", "rect( auto, auto, "+ (loc2 + 400  - scrollTop) +"px, auto)");
        }
        
    });
});
    
    
</script>    
 
</head>
<body>
    
    <section>
        <div class="desc">
            <div>Hello, World!</div>
            <div>I'm a boy.</div>
        </div>
    </section>
    
    <section>
        <div class="desc">
            <div>Good, morning!</div>
            <div>I'm a girl.</div>
        </div>
    </section>
    
    <section>
        <div class="desc">
            <div>Goodbye.</div>
            <div>We're friends.</div>
        </div>
    </section>
    
    <div class="scroll"></div>
    
</body>
</html>



http://crlog.com/2017/05311229.html