728x90
๋ฉ์ง ํํ์ด์ง๋ค์ ํ์ํ๋ ์ค ๊ด์ฐฎ์ ๋ณด์ด๋ ํจ๊ณผ๋ฅผ ๋ฐ๊ฒฌํด์ ์ง์ ๊ตฌํํด ๋ณด์์ต๋๋ค.
๋ค์๊ณผ ๊ฐ์ ํจ๊ณผ๋ฅผ ๊ตฌํํ๊ธฐ ์ํ ๊ตฌ์กฐ์ ๋ฐฉ์์ ๋ค์ํ๊ฒ ์ง๋ง,
์ ๋ ๋จ์ํ๊ฒ ๊ตฌํํ์์ต๋๋ค.
div ์์ inner_div๋ฅผ ๋๊ณ
์ฒซ๋ฒ์งธ์ค์ inner_div์๊ฒ๋ left -100% ๋ฅผ ๋๋ฒ์งธ ์ค์ inner_div์๊ฒ๋ left 100%๋ฅผ ์ฃผ์ด,
๋์์ left: 0์ด ๋ ๋ ๋ค์๊ณผ ๊ฐ์ ์ก์ ์ด ์ผ์ด๋๋๋ก ํ์์ต๋๋ค.
classํ๋๋ก ์ปจํธ๋กค ํ๊ธฐ ๋๋ฌธ์ javascript์ ๋จ์ํ class๋ง ์ถ๊ฐํด ์ฃผ๋ฉด ๋ฉ๋๋ค.
1. html
<div class="wrapper" >
<button class="button">Click Me</button>
<div class="container" style="background-image:url('./bg.jpg')">
</div>
<!-- divider s -->
<div class="divider">
<div class="row to_left">
<div class="block"><div class="inner-block"></div></div>
<div class="block"><div class="inner-block"></div></div>
<div class="block"><div class="inner-block"></div></div>
<div class="block"><div class="inner-block"></div></div>
</div>
<div class="row to_right">
<div class="block"><div class="inner-block"></div></div>
<div class="block"><div class="inner-block"></div></div>
<div class="block"><div class="inner-block"></div></div>
<div class="block"><div class="inner-block"></div></div>
</div>
</div>
<!-- divider e -->
</div>
2. css
html,body{
width:100%;
height:100%;
}
* {
padding:0;
margin:0;
}
.wrapper{
position: relative;
width:100%;
height:100%;
}
.container{
width:100%;
height:100%;
background-size: cover;
}
.button{
position: fixed;
top:20px;
right:20px;
z-index:100;
padding:20px;
font-size: 15px;
}
.divider{
position: fixed;
top:0;
left:0;
width: 100%;
height:100%;
z-index:10;
background:rgba(0,0,0,0.4);
display: flex;
flex-direction: column;
}
.divider .row{
flex: 1;
display:flex;
}
.divider .row:first-child{
border-bottom: 1px solid rgba(0,0,0,0.4);
}
.divider .row .block{
position: relative;
overflow:hidden;
border-right:1px solid rgba(0,0,0,0.4);
}
.divider .row .block:nth-child(1),
.divider .row .block:nth-child(4){
flex: 1;
}
.divider .row .block:nth-child(2),
.divider .row .block:nth-child(3){
flex: 2;
}
.divider .row .inner-block{
position: absolute;
top:0;
left:0;
z-index: 1;
width:100%;
height: 100%;
background-color:lightgrey;
transition: left 0.3s;
}
.divider .row.to_left .inner-block{ /* ์ฒซ ๋ฒ์งธ ์ค left -> right */
left:-100%;
}
.divider .row.to_right .inner-block{ /* ๋ ๋ฒ์งธ ์ค right -> left */
left:100%;
}
.divider .row.to_right.active .inner-block,
.divider .row.to_left.active .inner-block{
left:0;
}
3. script
var btn = document.querySelector('.button');
var rows = document.querySelectorAll('.row');
btn.addEventListener('click', function(){
if(rows[0].classList.contains('active')){
for(var i=0; i< rows.length; i++){
rows[i].classList.remove('active');
}
} else {
for(var i=0; i< rows.length; i++){
rows[i].classList.add('active');
}
}
});
์ฌ์ฌํด์ ๋ง๋ค์ด ๋ณธ ํ๋ฉด์ด์ง๋ง ์ด๋์ ์ธ ๋ฐ๊ฐ ์๋์ง ๋ชจ๋ฅด๊ฒ ๋ค์. ๐
๋ฐ์ํ
'๊ฐ๋ฐ ๐พ > Playground' ์นดํ ๊ณ ๋ฆฌ์ ๋ค๋ฅธ ๊ธ
ํ๋์ฉ ๋ํ๋๋ ํต ๋ฉ๋ด ๋ง๋ค๊ธฐ (SCSS & CSS) (0) | 2021.07.12 |
---|---|
ํคํจ๋๋ก ๋น๋ฐ๋ฒํธ ์ ๋ ฅํ๊ธฐ (HTML+SASS+JavaScript) (2) | 2021.07.08 |
javascript ์คํฌ๋กค ์ํ๋ฐ ๋ง๋ค๊ธฐ (window / div) (2) | 2021.07.01 |