※ animate를 사용하려면 position를 꼭 absoulte로 선언을 해야함
1. 애니메이트 예제
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>Document</title>
<script src="https://ajax.googleapis.com/ajax/libs/jquery/3.4.1/jquery.min.js"></script>
<script>
$(document).ready(function(){
$("button").click(function(){
// animate 대상 tag의 display속성을 absoulte로 선언해야함
$("div").animate({left: '250px'});
});
});
</script>
</head>
<body>
<button>Start Animation</button>
<p>By default, all HTML elements have a static position, and cannot be moved. To manipulate the position, remember to first set the CSS position property of the element to relative, fixed, or absolute!</p>
<!-- 애니메이션을 사용하려면 postion:absolute를 꼭 써줘야함!!-->
<div style="background:#98bf21;height:100px;width:100px;position:absolute;"></div>
</body>
</html>
1. 실행화면
2. 애니메이트 예제
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>Document</title>
<script src="https://ajax.googleapis.com/ajax/libs/jquery/3.4.1/jquery.min.js"></script>
<script>
$(document).ready(function(){
$("button").click(function(){
$("div").animate({
left: '250px',
opacity: '0.5',
height: '150px',
width: '150px'
});
});
});
</script>
</head>
<body>
<button>Start Animation</button>
<p>By default, all HTML elements have a static position, and cannot be moved. To manipulate the position, remember to first set the CSS position property of the element to relative, fixed, or absolute!</p>
<!-- 애니메이션을 사용하려면 postion:absolute를 꼭 써줘야함!!-->
<div style="background:#98bf21;height:100px;width:100px;position:absolute;"></div>
</body>
</html>
2. 실행화면
3. 애니메이트 예제
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>Document</title>
<script src="https://ajax.googleapis.com/ajax/libs/jquery/3.4.1/jquery.min.js"></script>
<script>
$(document).ready(function(){
$("button").click(function(){
$("div").animate({
left: '250px',
opacity: '0.5',
// += 150 px => height += 150px
// height: '150px',
height : 'toggle',
width: '+=150px'
});
});
});
</script>
</head>
<body>
<button>Start Animation</button>
<p>By default, all HTML elements have a static position, and cannot be moved. To manipulate the position, remember to first set the CSS position property of the element to relative, fixed, or absolute!</p>
<!-- 애니메이션을 사용하려면 postion:absolute를 꼭 써줘야함!!-->
<div style="background:#98bf21;height:100px;width:100px;position:absolute;"></div>
</body>
</html>
3. 실행화면
4. 애니메이트 예제
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>Document</title>
<script src="https://ajax.googleapis.com/ajax/libs/jquery/3.4.1/jquery.min.js"></script>
<script>
$(document).ready(function(){
$("button").click(function(){
// div : div tag에 해당하는 object(객체)를 말함
var div = $("div");
div.animate({height:'300px',opacity:'0.4'}, "slow");
div.animate({width:'300px',opacity:'0.8'}, "slow");
div.animate({height:'100px',opacity:'0.4'}, "slow");
div.animate({width:'100px',opacity:'0.8'}, "slow");
});
});
</script>
</head>
<body>
<button>Start Animation</button>
<p>By default, all HTML elements have a static position, and cannot be moved. To manipulate the position, remember to first set the CSS position property of the element to relative, fixed, or absolute!</p>
<!-- 애니메이션을 사용하려면 postion:absolute를 꼭 써줘야함!!-->
<div style="background:#98bf21;height:100px;width:100px;position:absolute;"></div>
</body>
</html>
'jQuery 수업' 카테고리의 다른 글
jQuery-10(css- color 적용) (0) | 2020.02.19 |
---|---|
jQuery-9(animate()- slideDown()) (0) | 2020.02.19 |
jQuery-7(이벤트 slideUp(), slideDown()) (0) | 2020.02.19 |
jQuery-6(이벤트 fadeIn(), fadeOut(), fadeTo(), fadeToggle()) (0) | 2020.02.19 |
jQuery-5(이벤트 toggle) (0) | 2020.02.19 |