This animation move blocks into parent blocks with overflow hidden(text is changing with same way). I want to make it with lesser coding and for using it for few same buttons. Actually this code hard to anderstand so i reccomend you to copy it watch what it does and try wright your verssion of it. Thanks for halping me out!
Html
<section class="setting__color color">
<h3 class="color__title">Color scheme:</h3>
<div class="color__buttons">
<button class="color__button" id="white">White
<span class="color__span " id="whitespan">
<span class="color__text " id="whitetext">White</span>
</span>
</button>
<button class="color__button" id="black">Black
<span class="color__span" id="blackspan">
<span class="color__text" id="blacktext">Black</span>
</span>
</button>
</div>
</section>
SCSS
.color {
margin: 50px;
&__title {
font-size: 18px;
color: #cacaca;
font-weight: normal;
}
&__buttons {
display: flex;
margin-top: 7px;
button {
margin-left: 5px;
:first-child {
margin-left: 0;
}
}
}
&__on {
width: 100px;
height: 40px;
background-color: #6844B5;
color: #fff;
font-size: 15px;
border-radius: 5px;
outline: 1px solid#6844B5;
position: relative;
top: 0;
left: 0;
}
&__button {
width: 100px;
height: 40px;
background-color: #fff;
color: #cacaca;
font-size: 15px;
border-radius: 5px;
outline: 1px solid#cacaca;
&:hover {
outline: 1px solid#6844B5;
transition: all ease-in-out 0.3s;
}
position: relative;
top: 0;
left: 0;
transition: all ease-in-out 0.3s;
overflow: hidden;
}
&__span {
position: absolute;
top: 0;
left: 0;
z-index: 2;
color: #cacaca;
width: 100%;
height: 100%;
background-color: #6844B5;
transition: all ease-in 1s;
outline: 1px solid#6844B5;
overflow: hidden;
display: block;
transform: translate3d(110%, 0px, 0px);
}
&__text {
display: block;
padding: 11px 0;
transition: all ease-in 1s;
transform: translate3d(-110%,0px , 0px);
}
}
#white{
background-color: #6844B5;
color: #fff;
}
#blacktext{
color: #fff;
}
#whitespan {
background-color: #fff;
outline: none;
}
.active-setting {
transform: translate3d(0px, 0%, 0px);
transition: all ease-in 1s;
}
JavaScript
const blackScheme = document.getElementById('black')
const blackSpan = document.getElementById('blackspan')
const blackText = document.getElementById('blacktext')
const whiteScheme = document.getElementById('white')
const whiteSpan = document.getElementById('whitespan')
const whiteText = document.getElementById('whitetext')
blackScheme.addEventListener('click', () => {
blackSpan.classList.add('active-setting')
blackText.classList.add('active-setting')
whiteSpan.classList.add('active-setting')
whiteText.classList.add('active-setting')
})
whiteScheme.addEventListener('click', () => {
blackSpan.classList.remove('active-setting')
blackText.classList.remove('active-setting')
whiteSpan.classList.remove('active-setting')
whiteText.classList.remove('active-setting')
})
I want to do less code and do it univerasal (to use many times, with same buttons)
