🧷
jQuery
  • 제이쿼리
  • 제이쿼리 기본
  • 선택자
    • 기본선택자
    • 계층 선택자
    • 속성 선택자
    • 기본 필터 선택자
    • 내용 필터 선택자
    • 보임 필터 선택자
    • 자식 요소 필터 선택자
    • 폼 요소 필터 선택자
  • 탐색
    • find()/filter()
  • 속성
    • position()/offset()
    • scrollTop()/scrollLeft()
    • addClass()/removeClass()
    • toggleClass()
    • hasClass()
    • attr()/removeAttr()
  • 변경
    • append() / prepend()
    • text()/html()
    • remove() / empty()
  • 애니메이션
    • show()/hide()
    • fadeIn()/fadeOut()
    • slideUp()/slideDown()
    • animate()
  • 이벤트
Powered by GitBook
On this page

Was this helpful?

  1. 속성

scrollTop()/scrollLeft()

scrollTop()메[서드는 브라우저의 스크롤바가 수직/수평으로 이동한 위치값을 불러오거나 변경할 때 사용합니다. scrollLeft()

$("선택자").scrollTop(); $("선택자").scrollLeft().

<!DOCTYPE html>
<html lang="ko">
<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>jQuery12_scroll</title>
<style>
    body {width: 10000px; height: 10000px;}
    div {
        width: 150px; 
        height: 150px; 
        color: #c7254e; 
        background-color: #f9f2f4; 
        border-radius: 50%; 
        border: 1px dashed #a51a3d; 
        text-align: center; 
        line-height: 150px;
    }
    .scrollTop {position: fixed; left: 30px; top: 10px;}
    .scrollTop::before {content: 'scrollTop ';}
    .scrollLeft {position: fixed; left: 200px; top: 10px;}
    .scrollLeft::before {content: 'scrollLeft ';}
</style>
</head>
<body>
<div class="scrollTop">0</div>
<div class="scrollLeft">0</div>
<!-- script -->
<script src="jquery.min_1.12.4.js"></script>
<script>
    $(window).scroll(function(){
        const scrollTop = $(window).scrollTop();
        const scrollLeft = $(window).scrollLeft();

        $(".scrollTop").text(parseInt(scrollTop));
        $(".scrollLeft").text(parseInt(scrollLeft));
    });
</script>
</body>
</html>
Previousposition()/offset()NextaddClass()/removeClass()

Last updated 4 years ago

Was this helpful?