scrolling to top

by 조쉬 posted Dec 22, 2016
?

단축키

Prev이전 문서

Next다음 문서

ESC닫기

크게 작게 위로 아래로 댓글로 가기 인쇄
<!doctype html>
<html>
<head>
<meta charset="UTF-8">
<title>top scrolling</title>
<style>
body {
    margin: 0;
}
.container {
    position: absolute;
    top: 0;
    bottom: 0;
    left: 0;
    right: 0;
}
aside {
    position: fixed;
    top: 0;
    left: 0;
    bottom: 0;
    width: 200px;
    background-color: orange;
}
article {
    position: absolute;
    top: 0;
    width: 1000px;
    right: 0;
    height: 1200px;
    background-color: yellow;
}
#btn-top {
    position: absolute;
    bottom: 0;
    left: 0;
    right: 0;
    height: 100px;
    background-color: red;
    cursor: pointer;
}
</style>
<script>
$(document).ready(function(){
    $("#btn-top").click(function(){
        $("html, body").animate({
            scrollTop: 0
        });
    });
});
</script>
</head>
 
<body>
    <div class="container">
        <aside></aside>
        <article>
            <div id="btn-top"></div>
        </article>
    </div>
</body>
</html>