 |
|
|  |
jQuery Effects - Animation |
|
|
 |
8³â Àü |
jQuery AnimationÀº ¾Ö´Ï¸ÞÀÌ¼Ç È¿°ú¸¦ ¸¸µé ¼ö ÀÖ½À´Ï´Ù.
±âº»ÀûÀÎ ¹®¹ýÀº $(selector).animate({params},speed,callback); »ç¿ëÇÕ´Ï´Ù.
animate() °£´ÜÇÑ ¼Ó¼º
animate()·Î CSS¼Ó¼ºÀ» Á¤ÀÇÇÒ ¼ö ÀÖ½À´Ï´Ù.
"slow", "fast", milliseconds ·Î ½Ã°£À» Á¤ÀÇÇÒ ¼ö ÀÖ½À´Ï´Ù.
°£´ÜÇÑ »ç¿ë ¹æ¹ýÀº ¾Æ·¡ ±¸¹®À» È®ÀÎÇØÁÖ¼¼¿ä. <div> ÀÇ ³»¿ëÀ» ¿ÞÂÊÀ¸·Î 250px À̵¿ÇÏ´Â ³»¿ëÀÔ´Ï´Ù.
$("button").click(function(){
$("div").animate({left:'250px'});
});
°ü·Ã¿¹Á¦
<!DOCTYPE html>
<html>
<head>
<script src="//ajax.googleapis.com/ajax/libs/jquery/1.9.1/jquery.min.js">
</script>
<script>
$(document).ready(function(){
$("button").click(function(){
$("div").animate({left:'250px'});
});
});
</script>
</head>
<body>
<button>¾Ö´Ï¸ÞÀÌ¼Ç È¿°ú</button>
<p>CSS¸¦ Á¤ÀÇÇÏ¿© ÁÂÃøÀ¸·Î 250px ¸¸Å div °ªÀ» À̵¿ÇÕ´Ï´Ù!</p>
<div style="background:#98bf21;height:100px;width:100px;position:absolute;">
</div>
</body>
</html>
// À̹ÌÁö¿¡¼ È®ÀεǵíÀÌ "¾Ö´Ï¸ÞÀÌ¼Ç È¿°ú" ¹öÆ°À» Ŭ¸¯ÇÏ¸é »ç°¢ÇüÀÌ ÁÂÃøÀ¸·Î 250px À̵¿µÈ ¸ð½ÀÀ» È®ÀÎÇÒ ¼ö ÀÖ½À´Ï´Ù.
animate() ÀÇ ¿©·¯°¡Áö ¼Ó¼º
$("button").click(function(){
$("div").animate({
left:'250px',
opacity:'0.5',
height:'150px',
width:'150px'
});
});
// ÁÂÃøÀ¸·Î 250px À̵¿ÇÏ°í, opacity 0.5´Â À̹ÌÁö¸¦ 0.5 ¸¸Å Åõ¸íµµÇÏ°Ô Çϴ°ÍÀ» ¸»ÇÕ´Ï´Ù.. Áï "50% À̹ÌÁö¸¦ Åõ¸íÇÏ°Ô Çضó"´Â ¶æÀÔ´Ï´Ù. °ªÀÌ 0¿¡ °¡±î¿ï¼ö·Ï Åõ¸íµµ´Â Ä¿Áö°Ô µË´Ï´Ù. ±×¸®°í height, width´Â ³ôÀÌ¿Í ³ÐÀ̸¦ 150px ¸¸Å ÁÖ°Ú´Ù´Â ÀÇ¹Ì ÀÔ´Ï´Ù. ÇöÀç Å©±â°¡ 100À̴ϱî 150¸¸Å Ä¿Áö°Ô µË´Ï´Ù.
°ü·Ã¿¹Á¦
<!DOCTYPE html>
<html>
<head>
<script src="//ajax.googleapis.com/ajax/libs/jquery/1.9.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>¾Ö´Ï¸ÞÀÌ¼Ç È¿°ú</button>
<p>ÁÂÃøÀ¸·Î 250px À̵¿ÇÏ°í Åõ¸íµµ¸¦ 0.5¸¦ ÁÖ¸ç, ³ôÀÌ¿Í ³ÐÀ̸¦ 150px¿¡ Ç϶ó!</p>
<div style="background:#98bf21;height:100px;width:100px;position:absolute;">
</div>
</body>
</html>
animate() ÀÇ »ó´ë°ª
$("button").click(function(){
$("div").animate({
left:'250px',
height:'+=150px',
width:'+=150px'
});
});
// ÁÂÃøÀ¸·Î 250px À̵¿ÇÏ°í, ³ôÀÌ¿Í ³ÐÀ̸¦ 100px ¸¸Å ´õÇ϶ó´Â ÀÇ¹Ì ÀÔ´Ï´Ù. Áï ¹öÆ°À» °è¼Ó Ŭ¸¯ ÇÒ¼ö·Ï À̹ÌÁö´Â Á¡Á¡´õ Ä¿Áö°Ô µË´Ï´Ù. ¿Ö³ÄÇϸé 100px¾¿ °è¼Ó °ªÀÌ Áõ°¡µÇ´Ï±î¿ä.
animate() ÀÇ ±âŸ ¼Ó¼º
¾Æ·¡ ±¸¹® ó·³ °ªÀ» "show", "hide", "toggle" ó·³ ÁÙ¼öµµ ÀÖ½À´Ï´Ù.
$("button").click(function(){
$("div").animate({
height:'toggle'
});
});
// ¸¶Âù°¡Áö ±âº» ÄÚµùÀº °°À¸¸ç height:'toggle' À» ÀÔ·ÂÇÏ¿© ¹Ù²ãº¸½Ã±â ¹Ù¶ø´Ï´Ù.
animate() ÀÇ °í±Þ±â´É
$("button").click(function(){
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");
});
// ÀÏ´Ü var º¯¼ö°ªÀ» ¼±¾ðÇÏ´Â ¸í·É¾îÀÔ´Ï´Ù. Áï var div=$("div"); div¿¡ $("div")À» ´ëÀÔ½ÃÅ°¶ó´Â ÀǹÌÀÔ´Ï´Ù. ±×·¸°Ô ÇÑ ÀÌÀ¯´Â ÄÚµùÀ» ÁÙ¿©ÁÖ´Â ¿ªÇÒµµ ÇÒ ¼ö ÀÖ°í, ÇϳªÀÇ ¼±¾ðÀ¸·Î ¿©·¯°³¸¦ ÇѲ¨¹ø¿¡ ó¸®ÇÏ´Ï ¼Õ½±°Ô ÄÚµùÀ» ÇÒ ¼öµµ ÀÖ°ÚÁÒ.
¾î¶µç À§ÀÇ Àǹ̴ ¹«¾ùÀΰí ÇÏ´Ï ÀÏ´Ü height 300px ¿Í opacity 0.4°¡ ³ª¿À´Âµ¥ À§¿¡¼µµ ¸»ÇßµíÀÌ height(³ôÀÌ)¸¦ 300pxÀ» ÁÖ°í 0.4¸¸Å Åõ¸íµµ¸¦ ÁÖ¶ó´Â ÀǹÌÀÔ´Ï´Ù. ¾Æ·¡ ÄÚµùµµ ¸¶Âù°¡Áö·Î Çؼ®ÇÏ¸é µË´Ï´Ù. ÀÌ·¸°Ô µÇ¸é div ³»¿ëÀÌ 4¹øÀ» ¿òÁ÷ÀÌ°Ô µË´Ï´Ù.
¶Ç ´Ù¸¥ ¿¹Á¦
$("button").click(function(){
var div=$("div");
div.animate({left:'100px'},"slow");
div.animate({fontSize:'3em'},"slow");
});
// ÁÂÃøÀ¸·Î 100px À̵¿ÇÏ°í fontSize Áï ±ÛÀÚ Å©±â¸¦ 3emÀ» ÁÖ´Â ÀÇ¹Ì ÀÔ´Ï´Ù. ±×¸®°í ¿·¿¡ slow ¿É¼ÇÀÌ Ãß°¡ µÇ¾î Àִµ¥ ¸» ±×´ë·Î ´À¸®°Ô Ç϶ó´Â ÀǹÌÀÔ´Ï´Ù. "fast"°ªÀ» ÁÖ¾î ºü¸£°Ô ÇÒ¼öµµ ÀÖ°ÚÁÒ.
|
|
̵̧ : 337 |
̵̧
¸ñ·Ï
|
|
|  |
|