MelonPeach

39. jquery Method [ .scrollTop() ] - 선택한 요소의 스크롤바 수직 위치를 반환하거나 위치를 정하는 메소드

 

문법


.scrollTop() 

 

예를 들어

 

$("div").scrollTop(); 

 

div태그 요소의 스크롤바 수직 위치를 가져옵니다.


 

 

 

예제 코드


<%@ page language="java" contentType="text/html; charset=UTF-8" pageEncoding="UTF-8"%>
<html>
	<head>
		<script src="//cdnjs.cloudflare.com/ajax/libs/jquery/3.2.1/jquery.min.js"></script>
		<title>Home</title>
		<style type="text/css">
		#a {
			width: 300px;
			height: 200px;
			overflow: auto;
		}
		</style>
	</head>
	<script type="text/javascript">
	
	    $(document).ready(function(){
	    	$("#btn").click(function(){
	    		alert($("#a").scrollTop());
	    		
	    	})
	    });
	</script>
	<body>
		<div id="a">
			<p>
				I will always remember
				The day you kissed my lips
				Light as a feather
				And it went just like this
				No, it's never been better
				Than the summer of 2002 (ooh)
				Uh, we were only eleven
				But acting like grown-ups
				Like we are in the present
				Drinking from plastic cups
				Singing, "Love is forever and ever"
				Well, I guess that was true
				Dancing on the hood in the middle of the woods
				On an old Mustang, where we sang
				Songs with all our childhood friends
				And it went like this, say
				Oops, I got 99 problems singing bye, bye, bye
				Hold up, if you wanna go and take a ride with me
				Better hit me, baby, one more time, uh
				Paint a picture for you and me
				On the days when we were young, uh
				Singing at the top of both our lungs
				Now we're under the covers
				Fast forward to eighteen
				We are more than lovers
				Yeah, we are all we need
				When we're holding each other
				I'm taken back to 2002 (ooh)
				Yeah
				Dancing on the hood in the middle of the woods
				On an old Mustang, where we sang
				Songs with all our childhood friends
				And it went like this, say
				Oops, I got 99 problems singing bye, bye, bye
				Hold up, if you wanna go and take a ride with me
				Better hit me, baby, one more time, uh
				Paint a picture for you and me
				On the days when we were young, uh
				Singing at the top of both our lungs
				On the day we fell in love
				Ooh ooh, ooh ooh
				On the day we fell in love
				Ooh ooh, ooh ooh
				Dancing on the hood in the middle of the woods
				On an old Mustang, where we sang
				Songs with all our childhood friends
				Oh, now
				Oops, I got 99 problems singing bye, bye, bye
				Hold up, if you wanna go and take a ride with me
				Better hit me, baby, one more time
				Paint a picture for you and me
				On the days when we were young, uh
				Singing at the top of both our lungs
				On the day we fell in love
				Ooh ooh, ooh ooh
				On the day we fell in love
				Ooh ooh, ooh ooh
				On the day we fell in love
				Ooh ooh, ooh ooh
				On the day we fell in love
				Ooh ooh, ooh ooh
				On the day we fell in love, love, love
			</p>
		</div>
		<button id="btn">버튼</button>
	</body>
</html>

 

 

 

실행 테스트


실행 테스트

이 글을 공유합시다

facebook twitter googleplus kakaostory naver