Слайдер из apple устройств
Слайдер из apple устройств, которые реализованы на CSS. За счет смены css класса происходит анимация появления следующего устройства.
HTML
<div class="container">
<div class="device iphone"></div>
<div class="buttons">
<span class="left"></span>
<span class="right"></span>
</div>
</div>
CSS
body {
margin: 0;
height: 100vh;
display: flex;
align-items: center;
justify-content: center;
background-color: #aaa;
}
.container {
width: 360px;
height: 350px;
position: relative;
display: flex;
flex-direction: column;
align-items: center;
justify-content: center;
}
.device,
.device::before,
.device::after {
transition: 0.4s cubic-bezier(0.5, 1.7, 0.5, 1.2);
}
.device {
position: relative;
box-sizing: border-box;
display: flex;
justify-content: center;
background: linear-gradient(120deg, #ddd 30%, #ccc 30%);
transform: translateY(-25%);
}
.device::before,
.device::after {
content: '';
position: absolute;
}
.iphone::before,
.mini::before,
.ipad::before {
width: 2px;
height: 2px;
border: solid #a5adbe;
border-width: 0 12px 0 2px;
}
.iphone::after,
.mini::after,
.ipad::after {
width: 8px;
height: 8px;
background-color: white;
border-radius: 50%;
}
.iphone {
width: 59px;
height: 124px;
border: solid #484f5e;
border-width: 18px 4px;
border-radius: 6px;
}
.iphone::before {
top: -10px;
}
.iphone::after {
bottom: -13px;
}
.mini {
width: 93px;
height: 138px;
border: solid #484f5e;
border-width: 14px 5px;
border-radius: 10px;
}
.mini::before {
top: -8px;
}
.mini::after {
bottom: -11px;
}
.ipad {
width: 134px;
height: 176px;
border: solid #484f5e;
border-width: 18px 13px;
border-radius: 12px;
}
.ipad::before {
top: -10px;
}
.ipad::after {
bottom: -13px;
}
.macbook {
width: 234px;
height: 155px;
border: 8px solid #484f5e;
border-radius: 7px 7px 0 0;
}
.macbook::before {
width: 294px;
height: 14px;
background-color: #e8ebf0;
top: calc(100% + 8px);
border-radius: 0 0 14px 14px;
}
.macbook::after {
width: 3px;
height: 3px;
background-color: #a5adbe;
top: -6px;
border-radius: 50%;
}
.imac {
width: 360px;
height: 215px;
box-shadow:
inset 0 14px #484f5e,
inset 14px 0 #484f5e,
inset -14px 0 #484f5e;
border-bottom: 33px solid #e8ebf0;
border-radius: 10px;
}
.imac::before {
width: 90px;
height: 0;
top: calc(100% + 33px);
border: solid transparent;
border-bottom-color: #e2e4e8;
border-width: 0 10px 47px 10px;
}
.imac::after {
width: 4px;
height: 4px;
background-color: #a5adbe;
top: 5px;
border-radius: 50%;
box-shadow: 0 191px 0 4px #464e5d;
}
.buttons {
position: absolute;
width: inherit;
font-size: 30px;
height: 2em;
bottom: 0;
display: flex;
justify-content: space-around;
}
.buttons > * {
position: relative;
width: 4em;
}
.buttons > *:active {
transform: scale(0.9);
filter: brightness(0.8);
}
.buttons > *::before {
position: absolute;
width: 2em;
height: 2em;
background-color: #484f5e;
color: silver;
text-align: center;
line-height: 2em;
border-radius: 1em;
cursor: pointer;
transition: 0.2s;
}
.buttons .left::before {
content: '←';
right: 0;
}
.buttons .right::before {
content: '→';
}
.buttons > *:hover::before {
width: 4em;
}
.buttons .left:hover::before {
content: '⟵';
}
.buttons .right:hover::before {
content: '⟶';
}
JS
const $ = (className) => document.getElementsByClassName(className)[0]
let devices = ['iphone', 'mini', 'ipad', 'macbook', 'imac']
let loop = {
'left': () => devices.unshift(devices.pop()),
'right': () => devices.push(devices.shift())
}
Array.from($('buttons').children).forEach(element =>
element.addEventListener('click', function(e) {
loop[e.target.className]()
$('device').className = 'device ' + devices[0]
})
)