animation
2023. 7. 28. 17:07ใjquery
animation?
js์ css๋ฅผ ์ด์ฉํด์ ์๋ฆฌ๋จผํธ์ ๋์ ์ธ ํจ๊ณผ ๋ถ์ฌ
jQuery์ ํจ๊ณผ ๋ฉ์๋๋ฅผ ํธ์ถํด์ ๊ฐ๋จํ ํจ๊ณผ ๋ถ์ฌ ๊ฐ๋ฅ
ex1)
<!DOCTYPE html>
<html>
<head>
<style>
body {
margin: 100px;
}
span {
color:red;
cursor:pointer;
}
div {
margin:3px;
width:80px;
height:80px;
}
div {
background:#f00;
}
</style>
<script src="http://code.jquery.com/jquery-latest.js"></script>
</head>
<body>
<input type="button" id="fadeout" value="fade out" />
<input type="button" id="fadein" value="fade in" />
<input type="button" id="hide" value="hide" />
<input type="button" id="show" value="show" />
<input type="button" id="slidedown" value="slide down" />
<input type="button" id="slideup" value="slide up" />
<input type="button" id="mix" value="mix" />
<div id="target">
target
</div>
<script>
$('input[type="button"]').click( function(e) {
var $this = $(e.target);
switch($this.attr('id')) {
case 'fadeout':
//์ด๋ฏธ์ง ์์ฐ์ค๋ฝ๊ฒ ์ฌ๋ผ์ง('์๋-์ซ์๋ ๊ฐ๋ฅ')
$('#target').fadeOut('slow');
break;
case 'fadein':
//์ด๋ฏธ์ง ์์ฐ์ค๋ฝ๊ฒ ๋ํ๋จ
$('#target').fadeIn('slow');
break;
case 'hide':
$('#target').hide();
break;
case 'show':
$('#target').show();
break;
case 'slidedown':
$('#target').hide().slideDown('slow');
break;
case 'slideup':
$('#target').slideUp('slow');
break;
case 'mix':
//์ฌ๋ฌ ์ ๋๋ฉ์ด์
๋ค์ค ์ ์ฉ 1์ด๊ฐ ์ ์ง(๋ฐ๋ฆฌ์ด) ๋๋ฒ์งธ ์ธ์๋ก ์ด๋ฒคํธ ๋ฐ์
$('#target').fadeOut('slow').fadeIn('slow').delay(1000).slideUp().slideDown('slow', function(){alert('end')});
break;
}
})
</script>
</body>
</html>
fade out : ์์ํ ์ฌ๋ผ์ง
fade in : ์์ํ ๋ํ๋จ
hide : ์จ๊น
show : ๋ํ๋ด๊ธฐ
silde down : ์ฌ๋ผ์ด๋ ํํ๋ก ๋ด๋ ค์ค๋ฉด์ ๋ํ๋จ
silde ip : ์ฌ๋ผ์ด๋ ํํ๋ก ์ฌ๋ผ๊ฐ๋ฉด์ ์ฌ๋ผ์ง
mix : ์ฌ๋ฌ ์ ๋๋ฉ์ด์ ๋ฉ์๋ ํผํฉ ๊ฐ๋ฅ
animate ๋ฉ์๋
๋ฌธ๋ฒ :
animate(์ต์ข
๊ฒฐ๊ณผ,์งํ ์๋)
ex2)
<!DOCTYPE html>
<html>
<head>
<style>
body {
margin: 100px;
}
div {
background-color:#bca;
width:100px;
border:1px solid green;
}
</style>
<script src="http://code.jquery.com/jquery-latest.js"></script>
</head>
<body>
<button id="go">
» Run
</button>
<div id="block">
Hello!
</div>
<script>
//์์ 2
$("#go").click( function() {
//animate ๋ฉ์๋์ ์ฒซ๋ฒ์งธ ์ธ์๋ก css ์ฝ๋ : ์ต์ข
๊ฒฐ๊ณผ์ ํด๋น ๋๋ ์ฝ๋
//์ต์ข
๊ฒฐ๊ณผ๋ก ๊ฐ๋ ์ค๊ฐ๋จ๊ณ๋ค์ ์์ฐจ์ ์ผ๋ก ๋ณด์ฌ์ฃผ๋ฉด์ ์ ๋๋ฉ์ด์
ํจ๊ณผ
$("#block").animate({
width: "300px",
//๋ถํฌ๋ช
๋
opacity: 0.4,
marginLeft: "50px",
fontSize: "30px",
borderWidth: "10px"
//๋๋ฒ์งธ ์ธ์ ์ซ์ > ์ ๋๋ฉ์ด์
์งํ ์๋ (3์ด)
}, 3000);
});
</script>
</body>
</html>
run ๋ฒํผ ํด๋ฆญ ์ > ์ง์ ํ ์ต์ข ๊ฒฐ๊ณผ๋ก ์ง์ ํ ์๊ฐ์ ๋ง์ถฐ์ ๋ณํ
'jquery' ์นดํ ๊ณ ๋ฆฌ์ ๋ค๋ฅธ ๊ธ
traversing(ํ์) (0) | 2023.07.28 |
---|---|
Form (0) | 2023.07.28 |
Mainpulation(์๋ฆฌ๋จผํธ ์ ์ด) (0) | 2023.07.28 |
event (0) | 2023.07.28 |
Chain (0) | 2023.07.27 |