๋ณธ๋ฌธ ๋ฐ”๋กœ๊ฐ€๊ธฐ
์‹œ๋„/๊ตญ๋น„์ง€์›

[D+53] Front-end ๋ฏธ๋‹ˆํ”„๋กœ์ ํŠธ 9์ผ์ฐจ : ๋ฆฌ์ฝ”๋”ฉ ์™„์„ฑ

by ๐Ÿ‡๋ฐ•๋ด‰๋ด‰๐Ÿ‡ 2022. 12. 6.

 

๊ตญ๋น„์ง€์› D+53

Front-end ๋ฏธ๋‹ˆํ”„๋กœ์ ํŠธ 9์ผ์ฐจ

- ๋ฆฌ์ฝ”๋”ฉ ์™„์„ฑ -

 


 

์˜ค๋Š˜ ํ•œ ์ผ

- ๋ฆฌ์ฝ”๋”ฉ ์™„์„ฑ

 

ํŒŒ์ผ ๊ตฌ์„ฑ ๋ฐ ๋‚ด์šฉ

 


• style.css

video {
  width: 100%;
  margin: 0 auto;
  z-index: -5;
  opacity: 0.8;
}

.show-section0 .section0-message{
  display: block;
}

.section2-message {
  position: fixed;
  top: 5em;
  left: 0;
  width: 100%;
  display: none;
  text-align: center;
  font-size: 5rem;
  font-weight: bold;
  opacity: 0;
}

.show-section2 .section2-message {
  display: block;
}

#section0-canvas {
  /* absolute - ์ด๋ฏธ์ง€๋ฅผ ๊ฐ€์žฅ์ƒ๋‹จ์— ์œ„์น˜์‹œ์ผœ์•ผ ํ•˜๊ธฐ ๋•Œ๋ฌธ์— ์ผ๋ฐ˜์ ์ธ ๋ฌธ์„œ์˜ ํ๋ฆ„์„ ์ œ๊ฑฐํ•œ๋‹ค. */
  position: fixed;
  left: 0;
  top: 0;
  width: 100%;
  z-index: -10;
  text-align: center;
}

 

• index.html

<!-- section2 -->
  <section class="section2">
    <p id="section2-message-0" class="section2-message">
      ์•„์นจ์— ์‚ฌ๊ณผ 1๊ฐœ<br>์ฑ™๊ฒจ๋ณด๋Š”๊ฑด ์–ด๋–จ๊นŒ์š”?
    </p>
    <video src="./video/apple.mp4" loop muted autoplay></video>
</section>

 

• main.js

// calcValue : ์• ๋‹ˆ๋ฉ”์ด์…˜์— ์ ์šฉํ•˜๊ธฐ ์œ„ํ•œ ๊ฐ’์„ CSSํ™” ํ•œ๋‹ค.
	//  - parameter : ๊ฐ์˜์—ญ์˜ ํˆฌ๋ช…๋„์„ค์ •๊ฐ’ ([0, 1, { start: 0.05, end: 0.14 }])
	//  - return : CSSํ™”ํ•œ ๊ฐ’
	const calcValue = function (value) 
	{
		let rate;
		let result;
		let height = sectionSet[currentSection].height;
	
		// ๋น„์œจ์— ๊ธฐ๋ฐ˜ํ•œ CSSํ™”ํ•œ ๊ฐ’
		let startValue = height * value[2].start;
		let endValue = height * value[2].end;
		let heightValue = endValue - startValue;
	
		// ์„ค์ •๋ฒ”์œ„์— ๋ฒ—์–ด๋‚ฌ์„ ๊ฒฝ์šฐ ๊ฐ’์˜ ๊ฐ€์žฅ ๋ ๊ฐ’์ธ value[0]๊ณผ value[1]๋กœ
		// ์ž„์˜๋กœ ๊ฐ’์„ ์ง€์ •ํ•ด์ค€๋‹ค.
		if(sectionYOffset < startValue)
		{
			result = value[0];
		}
		else if(sectionYOffset > endValue)
		{
			result = value[1];
		}
		else
		{
			rate = (sectionYOffset - startValue) / heightValue;
	
			result = (rate * (value[1] - value[0])) + value[0];
		}
		return result;
	};
	
// playAnimation : ์„น์…˜์— ๋”ฐ๋ฅธ ์• ๋‹ˆ๋ฉ”์ด์…˜ ๋™์ž‘ ์‹œํ‚ค๊ธฐ
	//  - parameter : x
	//  - return : x
	const playAnimation = function () 
	{
		let value;
		let opacityValue;
		let translateYValue;
		let messageValue;
	
		let imageIndex = 0;
			
	
		const yOffsetRate = sectionYOffset / sectionSet[currentSection].height;
	
		let canvasCtx;
		let images;
		let imageRange;
	
		switch (currentSection) 
		{
			case 0:		// section0
	
				// cnavas info
				canvasCtx = sectionSet[currentSection].elemInfo.canvas.getContext('2d');
				images = sectionSet[currentSection].imageSettingsValues.images;
				imageRange = sectionSet[currentSection].imageSettingsValues.imageRange;
	
				imageIndex = Math.floor(calcValue(imageRange));
				canvasCtx.drawImage(images[imageIndex], 0, 0);
	
				// opacitiy ๊ฐ’ ์ดˆ๊ธฐํ™”
				sectionSet[0].elemInfo.message.map((el) => {
					el.style.opacity = 0;
				});
	
				opacityValue = sectionSet[0].opacitySettingsValues;
				translateYValue = sectionSet[0].tanslateYSettingsValues;
				messageValue = sectionSet[0].elemInfo.message;
	
				// message0
				if (yOffsetRate < 0.15) 
				{
					value = calcValue(opacityValue.message0_opacity_out);
					messageValue[0].style.opacity = value;
						
					value = calcValue(translateYValue.message0_translateY_out);
					messageValue[0].style.transform = `translateY(${value}%)`;
				} 
				else if (yOffsetRate >= 0.15 && yOffsetRate < 0.25) 
				{
					value = calcValue(opacityValue.message0_opacity_in);
					messageValue[0].style.opacity = value;
	
					value = calcValue(translateYValue.message0_translateY_in);
					messageValue[0].style.transform = `translateY(${value}%)`;
				}
	
				// message1
				else if (yOffsetRate >= 0.25 && yOffsetRate < 0.35) 
				{
					value = calcValue(opacityValue.message1_opacity_out);
					messageValue[1].style.opacity = value;
	
					value = calcValue(translateYValue.message1_translateY_out);
					messageValue[1].style.transform = `translateY(${value}%)`;
				} 
				else if (yOffsetRate >= 0.35 && yOffsetRate < 0.45) 
				{
					value = calcValue(opacityValue.message1_opacity_in);
					messageValue[1].style.opacity = value;
	
					value = calcValue(translateYValue.message1_translateY_in);
					messageValue[1].style.transform = `translateY(${value}%)`;
				}
	
				// message2
				else if (yOffsetRate >= 0.45 && yOffsetRate < 0.55) 
				{
					value = calcValue(opacityValue.message2_opacity_out);
					messageValue[2].style.opacity = value;
	
					value = calcValue(translateYValue.message2_translateY_out);
					messageValue[2].style.transform = `translateY(${value}%)`;
				} 
				else if (yOffsetRate >= 0.55 && yOffsetRate < 0.65) 
				{
					value = calcValue(opacityValue.message2_opacity_in);
					messageValue[2].style.opacity = value;
	
					value = calcValue(translateYValue.message2_translateY_in);
					messageValue[2].style.transform = `translateY(${value}%)`;
				}
	
				// message3
				else if (yOffsetRate >= 0.65 && yOffsetRate < 0.75) 
				{
					value = calcValue(opacityValue.message3_opacity_out);
					messageValue[3].style.opacity = value;
	
					value = calcValue(translateYValue.message3_translateY_out);
					messageValue[3].style.transform = `translateY(${value}%)`;
				} 
				else if (yOffsetRate >= 0.75 && yOffsetRate < 0.85) 
				{
					value = calcValue(opacityValue.message3_opacity_in);
					messageValue[3].style.opacity = value;
	
					value = calcValue(translateYValue.message3_translateY_in);
					messageValue[3].style.transform = `translateY(${value}%)`;
				}
	
				else 
				{
					value = calcValue(sectionSet[currentSection].imageSettingsValues.image_in);
					sectionSet[currentSection].elemInfo.canvas.style.opacity = value;
				}
	
				break;
	
			case 1:		// section1
				break;
	
			case 2:		// section2
				// opacity ๊ฐ’ ์ดˆ๊ธฐํ™”
				sectionSet[2].elemInfo.message.map((el) => {
					el.style.opacity = 0;
				});
	
				opacityValue = sectionSet[2].opacitySettingsValues;
				translateYValue = sectionSet[2].tanslateYSettingsValues;
				messageValue = sectionSet[2].elemInfo.message;
	
				// message0
				if(yOffsetRate < 0.25)
				{
					value = calcValue(opacityValue.message0_opacity_out);
					messageValue[0].style.opacity = value;
	
					value = calcValue(translateYValue.message0_translateY_out);
					messageValue[0].style.transform = `translateY(${value}%)`;
				}
	
				else	// 0.25๋ฒ”์œ„ ์ง€๋‚˜๋ฉด opacity๋ฅผ 1๋กœ ๊ณ„์† ์œ ์ง€ํ•˜๋„๋ก ์„ค์ •
				{
					messageValue[0].style.opacity = 1;
				}
	
				break;
		}
	};

 

 


๊ฒฐ๊ณผํ™”๋ฉด

 

 

๋ฐ˜์‘ํ˜•

๋Œ“๊ธ€