//* Define variables and html elements
const sidebar = document.querySelector('.sidebar');
const arrow = document.querySelector('.arrow');
//* Add event listeners
sidebar.addEventListener('mouseout', () => {
arrow.style.transitionDelay = '0s';
sidebar.style.transitionDelay = '0.05s';
})
sidebar.addEventListener('mouseover', () => {
arrow.style.transitionDelay = '0.05s';
sidebar.style.transitionDelay = '0s';
})
* {
margin: 0;
padding: 0;
box-sizing: border-box;
}
body {
height: 100vh;
width: 100vw;
display: flex;
}
.sidebar {
position: fixed;
height: 100vh;
background-color: black;
width: 80px;
transition: all 0.5s ease;
z-index: 0;
}
.arrow {
position: relative;
left: 7.5px;
right: 7.5px;
top: 7.5px;
width: 65px;
height: 65px;
fill: rgb(115, 151, 162);
transition: all 0.5s ease;
z-index: 2;
}
.arrowBackground {
position: absolute;
top: 0;
width: 82px;
height: 80px;
background-color: rgb(30, 30, 30);
z-index: 1;
border: 2px solid rgb(50, 50, 50);
transition: all 0.5s ease;
}
.sidebar:hover {
width: 240px;
}
body:has(.sidebar:hover) .arrow {
transform: rotate(180deg);
left: 167.5px;
}
body:has(.sidebar:hover) .arrowBackground {
left: 160px;
}
当我将鼠标悬停在侧栏上时,箭头和侧栏需要 0.5 秒才能转换,但箭头背景类会立即执行此操作,我不知道为什么,我希望它需要 0.5 秒才能转换,但我不知道如何会修复它
我尝试重新排列一些代码,但没有任何效果,我尝试在 JavaScript 中设置转换延迟,但仍然不起作用
Copyright 2014-2026 https://www.php.cn/ All Rights Reserved | php.cn | 湘ICP备2023035733号