Notice
Recent Posts
Recent Comments
Link
일 | 월 | 화 | 수 | 목 | 금 | 토 |
---|---|---|---|---|---|---|
1 | 2 | 3 | 4 | 5 | ||
6 | 7 | 8 | 9 | 10 | 11 | 12 |
13 | 14 | 15 | 16 | 17 | 18 | 19 |
20 | 21 | 22 | 23 | 24 | 25 | 26 |
27 | 28 | 29 | 30 | 31 |
Tags
- 리스트
- 추가납입
- 자바스크립트
- jQuery
- 가입
- 교보
- 특약
- Java
- javascript
- 뇌출혈
- 중도인출
- 프론트엔드
- Vue.js
- 프로그래밍
- 심장질환
- 인출수수료
- 파이썬
- 웹개발
- 수수료
- 보험
- 코딩
- 납입
- python
- 교보생명
- 사망
- 문자열
- PythonProgramming
- 보험료
- 변환
- 급성심근경색증
Archives
- Today
- Total
SeouliteLab
jQuery .animate() 메서드의 활용 예제와 설명 본문
jQuery의 .animate() 메서드는 HTML 요소의 스타일 속성을 부드럽게 변경하는 데 사용됩니다. 이를 통해 웹 페이지에서 다양한 애니메이션 효과를 쉽게 추가할 수 있습니다. .animate() 메서드의 사용법과 몇 가지 예제를 살펴보겠습니다.
예제 1: 요소의 이동 애니메이션
<!DOCTYPE html>
<html>
<head>
<title>jQuery .animate() 예제</title>
<script src="https://code.jquery.com/jquery-3.6.0.min.js"></script>
<style>
#box {
width: 100px;
height: 100px;
background-color: red;
position: relative;
}
</style>
</head>
<body>
<div id="box"></div>
<script>
$(document).ready(function() {
$("#box").click(function() {
$(this).animate({ left: '+=100px' }, 1000);
});
});
</script>
</body>
</html>
위 코드에서는 id가 "box"인 요소를 클릭할 때마다 오른쪽으로 100px 이동하는 애니메이션을 보여줍니다.
예제 2: 요소의 크기 변경 애니메이션
<!DOCTYPE html>
<html>
<head>
<title>jQuery .animate() 예제</title>
<script src="https://code.jquery.com/jquery-3.6.0.min.js"></script>
<style>
#box {
width: 100px;
height: 100px;
background-color: blue;
}
</style>
</head>
<body>
<div id="box"></div>
<script>
$(document).ready(function() {
$("#box").click(function() {
$(this).animate({ width: '+=50px', height: '+=50px' }, 1000);
});
});
</script>
</body>
</html>
위 코드에서는 id가 "box"인 요소를 클릭할 때마다 가로와 세로 크기가 각각 50px씩 증가하는 애니메이션을 보여줍니다.
예제 3: 요소의 투명도 변경 애니메이션
<!DOCTYPE html>
<html>
<head>
<title>jQuery .animate() 예제</title>
<script src="https://code.jquery.com/jquery-3.6.0.min.js"></script>
<style>
#box {
width: 100px;
height: 100px;
background-color: green;
}
</style>
</head>
<body>
<div id="box"></div>
<script>
$(document).ready(function() {
$("#box").click(function() {
$(this).animate({ opacity: 0.5 }, 1000);
});
});
</script>
</body>
</html>
위 코드에서는 id가 "box"인 요소를 클릭할 때마다 투명도가 절반으로 줄어드는 애니메이션을 보여줍니다.
.animate() 메서드를 사용하면 CSS 속성의 값을 부드럽게 변경할 수 있습니다. 첫 번째 인자로는 변경할 CSS 속성과 값을 포함한 객체를 전달하고, 두 번째 인자로는 애니메이션의 지속 시간을 밀리초 단위로 전달합니다.
위 예제에서는 클릭이벤트를 통해 요소의 스타일 속성을 변경하여 애니메이션을 효과적으로 보여줍니다.
'프로그래밍' 카테고리의 다른 글
jQuery .fadeIn() 메서드의 활용 예제와 설명 (0) | 2024.04.01 |
---|---|
jQuery .delay() 메서드의 활용 예제와 설명 (0) | 2024.04.01 |
jQuery Deferred.then() 메서드의 활용 예제와 설명 (0) | 2024.04.01 |
jQuery Deferred.resolveWith() 메서드의 활용 예제와 설명 (0) | 2024.04.01 |
jQuery Deferred.resolve() 메서드의 활용 예제와 설명 (0) | 2024.04.01 |