작성
·
294
답변 5
2
자막 없이 보시느라 고생이 많으십니다 ㅠㅠ
setLayout 함수의 for문 설정 부분에 오타가 있네요~
sceneInfo,length를 sceneInfo.length로 바꾸어주세요~
(쉼표가 아니라 마침표로)
0
0
@charset 'utf-8';
html {
font-family: 'Abel', sans-serif;
font-family: 'Noto Sans', sans-serif;
font-size: 14px;
}
body {
overflow-x: hidden;
color: rgb(29, 29, 31);
letter-spacing: -0.05em;
background: white;
}
p {
line-height: 1.6;
}
a{
color: rgb(29,29,31);
text-decoration: none;
}
.global-nav{
position: absolute;
top: 0;
left: 0;
width: 100%;
height: 44px;
padding: 0 1rem;
}
.local-nav{
position: absolute;
top: 45px;
left: 0;
width: 100%;
height: 52px;
padding: 0 1rem;
border-bottom: 1px solid #ddd;
}
.global-nav-link,
.local-nav-links{
display: flex;
align-items: center;
height: 100%;
max-width: 1000px;
margin: 0 auto;
}
.global-nav-link{
justify-content: space-between;
}
.local-nav-links .product-name{
margin-right: auto;
font-size: 1.4rem;
font-weight: bold;
}
.local-nav-links a{
font-size: 0.8rem;
}
.local-nav-links a:not(.product-name){
margin-left: 2em;
}
.scroll-section{
border: 3px solid red;
padding-top: 50vh;
}
#scroll-section-0 h1{
font-size: 4rem;
text-align: center;
}
.main-message{
display: flex;
align-items: center;
justify-content: center;
margin: 5px 0;
height: 3em;
font-size: 2.5rem;
/* background: rgba(0,0,0,0.3); 확인하기*/
}
.main-message p{
font-weight: bold;
line-height: 1.2;
text-align: center;
}
.main-message small{
display: block;
font-size: 1rem;
margin-bottom: 0.5em;
}
#scroll-section-2 .main-message{
font-size: 3.5rem;
}
.description{
padding: 0 1rem;
font-size: 1.2rem;
color: #888;
max-width: 1000px;
margin: 0 auto;
}
.description strong{
float: left;
margin-right: 0.2em;
font-size: 3rem;
color: rgba(29,29,31);
}
/*html-font-size: 14px X .description strong- font-size: 3rem =42
X .description strong-margin-right: 0.2em = 8.4*/
.desc-message {
width: 50%;
font-weight: bold;
}
.pin{
width: 1px;
height: 100px;
background: rgb(29,29,31);
}
.mid-messaga{
max-width: 1000px;
margin: 0 auto;
padding: 0 1rem;
font-size: 2rem;
color: #888;
}
.mid-messaga strong{
color: rgb(29,29,31);
}
.canvas-caption{
padding: 0 1rem;
color: #888;
font-size: 1.2erm;
}
.footer{
display: flex;
align-items: center;
justify-content: center;
height: 7rem;
background: darkorange;
color: #fff;
}
.sticky-elem{
display: none;
position: fixed;
top: 0;
left: 0;
width: 100%;
}
#show-scene-0 #scroll-section-0 .sticky-elem,
#show-scene-1 #scroll-section-1 .sticky-elem,
#show-scene-2 #scroll-section-2 .sticky-elem,
#show-scene-3 #scroll-section-3 .sticky-elem{
display: block;
}
@media(min-width: 1024px){
#scroll-section-0 h1{
font-size: 9vw;
}
.main-message{
font-size: 4vw;
}
.description{
font-size: 2rem;
}
.description strong{
font-size: 6rem;
}
#scroll-section-2 .main-message{
font-size: 6vw;
}
.main-message small{
font-size: 1.5vw;
}
.desc-message {
width: 20%;
}
.mid-messaga{
font-size: 4vw;
}
.canvas-caption{
font-size: 2rem;
}
}
0
<!DOCTYPE html>
<html>
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<meta http-equiv="X-UA-Compatible" content="IE=edge">
<title>AirMug Pro</title>
<link rel="stylesheet" href="main.css">
<link rel="preconnect" href="https://fonts.googleapis.com">
<link rel="preconnect" href="https://fonts.gstatic.com" crossorigin>
<link href="https://fonts.googleapis.com/css2?family=Abel&family=Noto+Sans:ital,wght@1,700&display=swap" rel="stylesheet">
</head>
<body>
<div class="container">
<nav class="global-nav">
<div class="global-nav-link">
<a href="#" class="global-nav-item">Rooms</a>
<a href="#" class="global-nav-item">Ideas</a>
<a href="#" class="global-nav-item">Stores</a>
<a href="#" class="global-nav-item">Contact</a>
</div>
</nav>
<nav class="local-nav">
<div class="local-nav-links">
<a href="#" class="product-name">AirMug Pro</a>
<a href="#">개요</a>
<a href="#">제품사양</a>
<a href="#">구입하기</a>
</div>
</nav>
<section class="scroll-section" id="scroll-section-0">
<h1>AirMug Pro</h1>
<div class="sticky-elem main-message">
<p >온전히 빠져들게 하는<br>최고급 세라믹</p>
</div>
<div class="sticky-elem main-message">
<p>주변 맛을 느끼게 해주는<br>주변 맛 허용 모드</p>
</div>
<div class="sticky-elem main-message">
<p>온종일 편안한<br>맞춤형 손잡이</p>
</div>
<div class="sticky-elem main-message">
<p>새롭게 입가를<br>찾아온 매혹</p>
</div>
</section>
<section class="scroll-section" id="scroll-section-1">
<p class="description">
<strong>보통 스크롤 영역</strong>
Lorem ipsum dolor sit amet, consectetur adipisicing elit. Beatae est ipsa minima, eligendi error cum vel dolorum pariatur officia facilis ipsam voluptatibus ad quasi porro quod quisquam quidem tempora accusantium accusamus, quaerat aliquam velit exercitationem incidunt? Id vitae quisquam saepe quasi accusantium tempore enim! Aperiam dolorum a vero repellat dolor, inventore ab odit totam molestias expedita? Enim quia dolor maiores veniam ea! Quam illo, est incidunt ipsa reiciendis modi quisquam reprehenderit fuga velit dolorem odit sequi autem blanditiis, ullam commodi quibusdam. Accusamus repellat aperiam quis neque laudantium, dignissimos hic nisi magnam praesentium enim beatae sint architecto cum numquam inventore rerum animi sed nostrum quae delectus, voluptas molestiae placeat aliquid! Vel quaerat error officiis magnam dolorum iste aspernatur at est! Quo, consequuntur? Reiciendis, dolor. Quo at cupiditate in iure obcaecati voluptatum vel ea! Ab vel harum facere hic fuga ducimus sapiente dolore dolorem, nobis sint perferendis cumque esse! Omnis fugiat sint error laborum eveniet labore nam ducimus quisquam in repudiandae impedit excepturi dignissimos tenetur libero placeat rerum maxime tempore, aut nihil. Qui, quam? Voluptate fuga possimus itaque quas nesciunt iste, facilis mollitia illo qui placeat temporibus inventore obcaecati. Recusandae, sequi dignissimos in natus eum maiores dolorem, deleniti nobis accusantium, aspernatur beatae.
</p>
</section>
<section class="scroll-section" id="scroll-section-2">
<div class="sticky-elem main-message a">
<p>
<small>편안한 촉감</small>
입과 하나 되다
</p>
</div>
<div class="sticky-elem desc-message b">
<p>
편안한 목넘김을 완성하는 디테일한 여러 구성 요소들, 우리는 이를 하나하나 새롭게 살피고 재구성하는 과정을 거쳐 새로운 수준의 머그, AirMug Pro를 만들었습니다. 입에 뭔가 댔다는 감각은 어느새 사라지고 오롯이 당신과 음료만 남게 되죠.
</p>
<div class="pin"></div>
</div>
<div class="sticky-elem desc-message c">
<p>
디자인 앤 퀄리티 오브 스웨덴,<br>메이드 인 차이나
</p>
<div class="pin"></div>
</div>
</section>
<section class="scroll-section" id="scroll-section-3">
<p class="mid-messaga">
<strong>Retina 머그</strong><br>
아이디어를 광활하게 펼칠<br>
아름답고 부드러운 음료 공간.
</p>
<!-- <canvas class="image-blend-canvas" width="1920" height="1080"></canvas>-->
<p class="canvas-caption">
Lorem ipsum dolor, sit amet consectetur adipisicing elit. Eveniet at fuga quae perspiciatis veniam impedit et, ratione est optio porro. Incidunt aperiam nemo voluptas odit quisquam harum in mollitia. Incidunt minima iusto in corporis, dolores velit. Autem, sit dolorum inventore a rerum distinctio vero illo magni possimus temporibus dolores neque adipisci, repudiandae repellat. Ducimus accusamus similique quas earum laborum. Autem tempora repellendus asperiores illum ex! Velit ea corporis odit? Ea, incidunt delectus. Sapiente rerum neque error deleniti quis, et, quibusdam, est autem voluptate rem voluptas. Ratione soluta similique harum nihil vel. Quas inventore perferendis iusto explicabo animi eos ratione obcaecati.
</p>
</section>
<footer class="footer">
2020, 1분코딩
</footer>
</div>
<script src="main.js"></script>
</body>
</html>
0
(()=>{
let y0ffset = 0 ; //window.pageYOffset 대신 쓸 변수
let prevScrollHeight = 0; //현재 스크롤 위치(yOffset)보다 이전에 위치한 스크롤 섹션들의 스크롤 높이값의 합
let currentScene = 0; //현재 활성화된(눈 앞에 보고있는) 씬(scroll-section)
// const arr =[1,2,3];
const sceneInfo = [
{//스크롤 높이 0
type: 'sticky',
heightNum: 5, //브라우저 높이의 5배로 scrollHeight 세팅
scrollHeight: 0,
objs: {
container: document.querySelector('#scroll-section-0')
}
},
{ //1
type: 'normal',
heightNum: 5,
scrollHeight: 0,
objs: {
container: document.querySelector('#scroll-section-1')
}
},
{ //2
type: 'sticky',
heightNum: 5,
scrollHeight: 0,
objs: {
container: document.querySelector('#scroll-section-2')
}
},
{ //3
type: 'sticky',
heightNum: 5,
scrollHeight: 0,
objs: {
container: document.querySelector('#scroll-section-3')
}
},
];//물론 여기서도 그렇게 세팅할 수 있지만,
//어차피 창 사이즈 변경에도 대응해야해서 따로 함수로 처리함
function setLayout(){
//각 스크롤 섹션의 높이 세팅
for (let i = 0; i < sceneInfo,length; i++){
sceneInfo[i].scrollHeight = sceneInfo[i].heightNum * window.innerHeight;
sceneInfo[i].objs.container.style.height = '${sceneInfo[i].scrollHeight}px';
}
console.log(sceneInfo);
}
// let y0ffset = 0;
function scrollLoop(){
// y0ffset = window.pageYOffset;
// console.log(y0ffset);
prevScrollHeight = 0;
for(let i = 0; i < currentScene; i++){
prevScrollHeight += sceneInfo[i].scrollHeight;
}
// console.log(prevScrollHeight);
if(y0ffset > prevScrollHeight + sceneInfo[currentScene].scrollHeight) {
currentScene++;
}
if(y0ffset < prevScrollHeight){
if(currentScene === 0) return; //브라우저 바운스 효과로 인해 마이너스가 되는 것을 방지(모바일)
currentScene--;
}
// console.log(currentScene);
document.body.setAttribute('id','show-scenes-${currentScene}');
}
window.addEventListener('resize', setLayout);
window.addEventListener('scroll', () => {
y0ffset = window.pageYOffset;
scrollLoop();
});
setLayout();
})();
//(function() {})();
//comsole.log(arr);