๋ณธ๋ฌธ ๋ฐ”๋กœ๊ฐ€๊ธฐ
Lect & Tip/javascript, jQuery

โœˆ jquery animate ์‚ฌ์šฉ์˜ˆ

by ๋‚ฏ์„ ๊ณต๊ฐ„2019 2019. 7. 17.

๋ชฉ์ฐจ

    jquery animate ์‚ฌ์šฉ์˜ˆ

    .animate() ํ•จ์ˆ˜๋ฅผ ์ด์šฉํ•˜๋ฉด html Element ์ƒ์˜ ๊ฐ์ฒด ์›€์ง์ž„์„ ๋ถ€์—ฌํ•  ์ˆ˜ ์žˆ๋‹ค.

    ๋ฐ˜๋“œ์‹œ CSS ์†์„ฑ ๋งต ๋ฐ์ดํ„ฐ์™€ ํ•จ๊ป˜ ์‚ฌ์šฉํ•œ๋‹ค.

    ์›€์ง์ž„์— ๊ด€๋ จ๋œ ์†์„ฑ๋“ค์€ ๋‹จ์ˆ˜ ์ˆ˜์น˜ ๊ฐ’(single numeric value)์„ ์ด์šฉํ•œ๋‹ค.

    ์ฆ‰, width, height, left, margin ๋“ฑ์— ์ด์šฉํ•  ์ˆ˜ ์žˆ์ง€๋งŒ color๊ฐ™์€ ๊ฐ’์—๋Š” ์‚ฌ์šฉํ•  ์ˆ˜ ์—†๋‹ค.

    .animate( properties [, duration] [, easing] [, complete] ) Returns : jQuery 

    Duration์€ ์ง€์†์‹œ๊ฐ„์ด๋ฉฐ, complete์—๋Š” ์ฝœ๋ฐฑ ํ•จ์ˆ˜๋ฅผ ์ง€์ •ํ•ด์„œ, ์• ๋‹ˆ๋ฉ”์ด์…˜ ๋™์ž‘ ์ดํ›„ ํ•จ์ˆ˜๋ฅผ ์‹คํ–‰ํ•  ์ˆ˜ ์žˆ๋‹ค.

    ๋‹จ, ์ด ํ•จ์ˆ˜์—๋Š” ์ธ์ž๊ฐ’์„ ๋„˜๊ฒจ ์ค„ ์ˆ˜๋Š” ์—†๋‹ค.

    • .animate( properties [, duration] [, easing] [, complete] )
    • properties ์›€์ง์ž„์„ ๋งŒ๋“ค์–ด ๋‚ผ์ˆ˜ ์žˆ๋Š” CSS ์†์„ฑ๋“ค
    • duration ์›€์ง์ž„์ด ๋ฐœ์ƒํ•  ์‹œ๊ฐ„
    • easing ์›€์ง์ž„์— ๋ณ€ํ™”๋ฅผ ์ค„ ์ˆ˜ ์žˆ๋Š” ํ•จ์ˆ˜
    • complete ์›€์ง์ž„์ด ๋ฉˆ์ถ˜ ํ›„ ์‹คํ–‰๋  ํ•จ์ˆ˜
    • .animate( properties, options )
    • properties ์›€์ง์ž„์„ ๋งŒ๋“ค์–ด ๋‚ผ์ˆ˜ ์žˆ๋Š” CSS ์†์„ฑ๋“ค
    • options A map of additional options to pass to the method. Supported keys:
    • duration: ์›€์ง์ž„์ด ๋ฐœ์ƒํ•  ์‹œ๊ฐ„
    • easing: ์›€์ง์ž„์— ๋ณ€ํ™”๋ฅผ ์ค„ ์ˆ˜ ์žˆ๋Š” ํ•จ์ˆ˜
    • complete: ์›€์ง์ž„์ด ๋ฉˆ์ถ˜ ํ›„ ์‹คํ–‰๋  ํ•จ์ˆ˜
    • step: ์›€์ง์ž„ ๊ฐ ์Šคํ…๋ณ„๋กœ ์‹คํ–‰๋  ํ•จ์ˆ˜
    • queue: ์• ๋‹ˆ๋ฉ”์ด์…˜ ํšจ๊ณผ๋Š” ์ˆœ์„œ๋Œ€๋กœ ๋ฐœ์ƒํ•ฉ๋‹ˆ๋‹ค. ๋งŒ์•ฝ false๋กœ ํ•˜๋ฉด ๋™์‹œ์— ๊ฐ™์ด ์›€์ง์ž„์ด ์ผ์–ด๋‚ฉ๋‹ˆ๋‹ค.
    • specialEasing: CSS ์†์„ฑ์˜ ํ•˜๋‚˜ ์ด์ƒ์„ ํŠน๋ณ„ํ•œ ํšจ๊ณผ๋กœ ์ฒ˜๋ฆฌํ•ฉ๋‹ˆ๋‹ค. (added 1.4).

    ์ขŒ์ธก ๋ฉ”๋‰ด๊ฐ€ ์„œ์„œํžˆ ๋‹ซํžˆ๊ฒŒ ํ•˜๋Š” ์ œ์ด์ฟผ๋ฆฌ๋‹ค.

    ๊ธฐ๋ณธ ์ ์œผ๋กœ ๊ฐ€์žฅ ๊ฐ„๋‹จํ•œ ๋ฐฉ๋ฒ•์ด๋‹ค.

    $(document).ready(function(){
    	// LNB ๋ฉ”๋‰ด ์ ‘๋Š” ๊ธฐ๋Šฅ
    	$('#menu_menuFix').click(function(){
    		var menuInitC = $('#menuInit').attr("value");
    		var timeToAnimate = 100;
    		if(menuInitC==0) { 
    			$('.lnb').animate({width:"240px"},timeToAnimate);
    			$('#menuInit').val('1');
    		} //if menu collapse then lanb width is 240px;
    		else if (menuInitC==1) {
    			$('.lnb').animate({width:"70px"},timeToAnimate);
    			$('#menuInit').val('0');
    		} //if menu collapse then lanb width is 70px;	
    	}); 
    });
    

    ๋ฐ˜์‘ํ˜•

    ๋Œ“๊ธ€