๊ตญ๋น์ง์ 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;
}
};
๊ฒฐ๊ณผํ๋ฉด
๋ฐ์ํ
๋๊ธ