๋ณธ๋ฌธ ๋ฐ”๋กœ๊ฐ€๊ธฐ
๐ŸŒŒ | WEB DEV/HTML CSS

CSS _transition(1) (property, timing, delay)

by KASSID 2022. 1. 14.

๋ชฉ์ฐจ

    728x90

    ์ €๋ฒˆ์— css๊ฐ€์ƒํด๋ž˜์Šค hover๋ฅผ ์•Œ์•„๋ณผ ๋•Œ ์ž ์‹œ ๋‹ค๋ค˜๋˜

    transition์— ๋Œ€ํ•ด์„œ ์ข€ ๋” ๊ณต๋ถ€ํ•ด๋ณด์•˜๋‹ค.

     

    transition = ๋ณ€๊ฒฝ ์ด๋‹ค.

     

    ๋”ฐ๋ผ์„œ ์š”์†Œ์˜ ์ƒํƒœ ๋ณ€ํ™”๋ฅผ ๋‹ค๋ฃฐ ์ˆ˜ ์žˆ๋Š”๋ฐ

     

    transition์€ ๋‹จ์ถ• ์†์„ฑ์ด๊ณ 

    property, duration, delay, timing-function

    ์ด๋ ‡๊ฒŒ 4๊ฐ€์ง€๊ฐ€ ์žˆ๋‹ค.

     

    ๊ฐ๊ฐ์„ ๊ฐ„๋‹จํžˆ ์•Œ์•„๋ณด๋ฉด

    1. property : ๋ณ€ํ™”๋ฅผ ์ ์šฉ์‹œํ‚ฌ CSS ์†์„ฑ ์ง€์ •

    2. duration : ๋ณ€ํ™”์‹œ๊ฐ„ ์ง€์ •

    3. delay : ์ง€์—ฐ ์‹œ๊ฐ„ ์ง€์ • (์‹œ๊ฐ„ ์ง€๋‚œ ํ›„ ์‹œ์ž‘)

    4. timing-function : ๋ณ€ํ™”๋˜๋Š” ๊ณผ์ • ์ค‘ ์†๋„ ์ง€์ •


     property & duration 

    div:hover {
    	transition-property: width;
    	transition-duration: 1s;
    }

    ์ €๋ฒˆ ํฌ์ŠคํŠธ์—์„œ ๋‹ค๋ค˜๋˜ ๊ฒƒ์ด ์ด ๋‘ ๊ฐœ์˜ ์†์„ฑ์ด์—ˆ๋‹ค.

     

    property๋Š” ๊ธฐ๋ณธ ๊ฐ’์ด ์†์„ฑ ์ „์ฒด์ด๋‹ค.

    ๋”ฐ๋ผ์„œ ์œ„์™€ ๊ฐ™์ด ์ง€์ •์„ ํ•ด์ฃผ๋ฉด ํ•ด๋‹น ์†์„ฑ์— ๋Œ€ํ•ด์„œ๋งŒ

    ๋ณ€๊ฒฝ ํšจ๊ณผ๋ฅผ ์ ์šฉํ•  ์ˆ˜ ์žˆ๋‹ค.

     

     

    ์ด๋•Œ ์†์„ฑ๊ณผ ์‹œ๊ฐ„์€ ์—ฌ๋Ÿฌ ๊ฐœ ๊ทธ๋ฆฌ๊ณ  ๋”ฐ๋กœ ์ง€์ •์„ ํ•  ์ˆ˜ ์žˆ๋‹ค.

     

    ์˜ˆ์‹œ 1)

    div {
        background: blueviolet;
        transition-property: width, background-color;
        transition-duration: 1s, 5s;
    }
    
    div:hover {
        width: 400px;
        background-color:white;
    }

    ๋ฐฐ์† ๋ฒ„์ „์ด์ง€๋งŒ

    width์™€ background-color์˜ ๋ณ€๊ฒฝ ์†๋„๊ฐ€

    ๋‹ค๋ฅธ ๊ฒƒ์„ ํ™•์‹คํžˆ ์•Œ ์ˆ˜ ์žˆ๋‹ค.

     

     

    ์œ„์ฒ˜๋Ÿผ ์—ฌ๋Ÿฌ ๊ฐœ์˜ ์†์„ฑ์„ ์ฃผ๊ณ  ์‹ถ์„ ๋•Œ์—๋Š”

    , (์ฝค๋งˆ)๋กœ ๊ตฌ๋ถ„์„ ํ•˜๋ฉด ๋œ๋‹ค.

     

     

    ์˜ˆ์‹œ 2)

    div {
        background: blueviolet;
        transition-property: width, background-color;
        transition-duration: 1s;
    }

    ์œ„์™€ ๊ฐ™์ด duration์— ํ•œ ๊ฐœ์˜ ์†์„ฑ๋งŒ ์ค€ ๊ฒฝ์šฐ,

    ๋‘ ์†์„ฑ์— ๊ฐ™์€ ๋ณ€ํ™” ์‹œ๊ฐ„์ด ์ ์šฉ์ด ๋œ๋‹ค.


     delay 

    ์ง€์—ฐ์‹œ๊ฐ„์„ ๋‹ค๋ฃจ๋Š” ์†์„ฑ์— ๋Œ€ํ•ด์„œ ์•Œ์•„๋ณด์ž

    div {
        background: blueviolet;
        transition-property: width, height, opacity;
        transition-duration: 1s;
        transition-delay: 0s, 1s, 1s;
    }
    
    div:hover {
        width: 200px;
        height: 200px;
        opacity: 0.5;
    }

    ์ง€์—ฐ ์‹œ๊ฐ„ ์—ญ์‹œ ์—ฌ๋Ÿฌ ์†์„ฑ์— ๋”ฐ๋กœ ์ง€์ •์„ ํ•  ์ˆ˜ ์žˆ๊ณ ,

    ๋ชจ๋‘ ๋™์ผ ํ•˜๊ฒŒ ์ ์šฉํ•˜๋Š” ๊ฒƒ๋„ ๊ฐ€๋Šฅํ•˜๋‹ค.

     

     

    timing-function์€ ๋‹ค์Œ ํฌ์ŠคํŠธ์—์„œ ๋‹ค๋ค˜๋‹ค!

    (https://bluishhot-star.tistory.com/83)

     

     

    ์ถœ์ฒ˜ : MDN(https://developer.mozilla.org/en-US/docs/Web/CSS/transition)

    ๋Œ“๊ธ€