ํ‹ฐ์Šคํ† ๋ฆฌ ๋ทฐ


๋‹ค์Œ๊ณผ ๊ฐ™์ด Progress-Bar๋ฅผ ๊ตฌํ˜„ํ•  ๋•Œ, ๋ฒ„ํŠผ์„ ํด๋ฆญํ•œ ๋’ค์— ์ง„ํ–‰ ๋ฐ” ์š”์†Œ์˜ width ๊ฐ’์ด 25%๊ฐ€ ๋˜์—ˆ์„ ๊ฒฝ์šฐ ํ•ด๋‹น ์• ๋‹ˆ๋ฉ”์ด์…˜์„

์ข…๋ฃŒ์‹œํ‚ค๊ธฐ ์œ„ํ•ด์„œ ๋‹ค์Œ๊ณผ ๊ฐ™์ด ์ฝ”๋“œ๋ฅผ ์ž‘์„ฑํ•˜์˜€๋‹ค.

if(elem.style.getPropertyValue('width') === range * current) { //ํ˜„์žฌ ์ง„ํ–‰ ๋ฐ” ๊ฐ€๋กœ ๋„ˆ๋น„๊ฐ€ ์ง€์ • 25%์— ๋„๋‹ฌํ–ˆ์„ ๊ฒฝ์šฐ
      clearInterval(intervalId); //์• ๋‹ˆ๋ฉ”์ด์…˜ ์ข…๋ฃŒ
      current++;
    }

ํ•˜์ง€๋งŒ ์›ํ•˜๋Š” ๊ฒฐ๊ณผ๋ฅผ ์–ป์ง€ ๋ชปํ•˜๊ณ  ์ง„ํ–‰ ๋ฐ”๋Š” ๋™์ž‘์ด ์ข…๋ฃŒ๋˜์ง€ ์•Š์€ ์ฑ„ ๋ฌดํ•œ ๋ฃจํ”„๋กœ ๋น ์ง€๋Š” ๋ฌธ์ œ๊ฐ€ ๋ฐœ์ƒํ•˜์˜€๋‹ค.

 

getPropertyValue์˜ ๋ฐ˜ํ™˜๊ฐ’

๋ฌธ์ œ getPropertyValue๊ฐ€ ๋ฐ˜ํ™˜ํ•˜๋Š” ๋ฐ์ดํ„ฐ ํƒ€์ž…์— ๋ฌธ์ œ๊ฐ€ ์žˆ์—ˆ๋‹ค.

The CSSStyleDeclaration.getPropertyValue() method interface returns a DOMString containing the value of a specified CSS property.
A DOMString is a sequence of 16-bit unsigned integers, typically interpreted as UTF-16 code units. This corresponds exactly to the JavaScript primitive String type

 

getPropertyValue๊ฐ€ ๋ฐ˜ํ™˜ํ•˜๋Š” ๊ฐ’์˜ ๋ฐ์ดํ„ฐ ํƒ€์ž…์€ String type์ด๊ธฐ ๋•Œ๋ฌธ์— ๋ฐ์ดํ„ฐ ํƒ€์ž… ๋ถˆ์ผ์น˜๋กœ ํ•ด๋‹น ์กฐ๊ฑด๋ฌธ์ด ์ œ๋Œ€๋กœ ์ˆ˜ํ–‰ํ•˜์ง€ ์•Š์•˜๋˜ ๊ฒƒ์ด๋‹ค.

if(parseFloat(elem.style.getPropertyValue('width')) === range * current) {
      clearInterval(intervalId);
      current++;
    }

์ด๋ฅผ ํ•ด๊ฒฐํ•˜๊ธฐ ์œ„ํ•ด ๋‹ค์Œ๊ณผ ๊ฐ™์ด parseFloat()๋ฅผ ์‚ฌ์šฉํ•˜์—ฌ ๋ฐ์ดํ„ฐ ํƒ€์ž…์„ ์ˆซ์ž๋กœ ํ˜•๋ณ€ํ™˜ ํ•ด์ฃผ์—ˆ๋‹ค.

(ํ•ด๋‹น ์ง„ํ–‰ ๋ฐ” 10ms ๋‹น 2.5์”ฉ ์ฆ๊ฐ€ํ•˜๊ธฐ ๋•Œ๋ฌธ์— ์†Œ์ˆ˜์ ์„ ๋ฐ˜ํ™˜ํ•˜๋Š” parseFloat๋ฅผ ์‚ฌ์šฉ)

๋Œ“๊ธ€
๊ณต์ง€์‚ฌํ•ญ
์ตœ๊ทผ์— ์˜ฌ๋ผ์˜จ ๊ธ€
์ตœ๊ทผ์— ๋‹ฌ๋ฆฐ ๋Œ“๊ธ€
Total
Today
Yesterday
๋งํฌ
TAG
more
ยซ   2024/10   ยป
์ผ ์›” ํ™” ์ˆ˜ ๋ชฉ ๊ธˆ ํ† 
1 2 3 4 5
6 7 8 9 10 11 12
13 14 15 16 17 18 19
20 21 22 23 24 25 26
27 28 29 30 31
๊ธ€ ๋ณด๊ด€ํ•จ