【发布时间】:2021-01-12 12:56:35
【问题描述】:
当您将鼠标悬停在导航菜单按钮上时,Atm 我正在尝试重新创建 SVG 圆形动画,如本网站所示:https://5scontent.com/。在我的网站上,圆圈会在刷新时出现,然后消失。
* {
margin: 0;
padding: 0;
font-family: 'Alata';
}
.container {
width: 100%;
min-height: 100vh;
background-position: center center;
background-repeat: no-repeat;
background-attachment: fixed;
background-size: cover;
background-color: black;
position: relative;
z-index: 1;
}
.navbar {
width: 90%;
height: 10vh;
margin: auto;
display: flex;
align-items: center;
}
.logo {
width: 120px;
cursor: pointer;
}
nav {
flex: 1;
text-align: right;
}
.svg-container{
position: absolute;
}
.svg{
position: absolute;
top: 0px;
left: 1125px;
}
.symbol {
fill: transparent;
stroke: white;
stroke-width: 1px;
stroke-dasharray: 150;
stroke-miterlimit: 10;
stroke-dashoffset: 150;
transition: all 3s linear;
}
nav ul li a:hover + .svg-container .symbol{
stroke-dashoffset: 0;
}
nav ul li {
list-style: none;
display: inline-block;
margin-left: 60px;
}
nav ul li a{
text-decoration: none;
color: white;
font-size: 14px;
padding: 5px 2px;
}
<body>
</div>
<div class="container">
<div class="navbar">
<nav>
<ul>
<li><a href="#">Home</a></li>
<div class="svg-container">
<svg width="100" height="100" class="svg">
<circle cx="50" cy="10" r="4" stroke-width="4" class="symbol"/>
</svg>
</div>
<li><a href="#">Work</a></li>
</ul>
</nav>
这是我在这里提出的第一个问题,如果我以一种更令人困惑的方式将它放在一起,那么请告诉我。 :)
【问题讨论】:
-
您正在使用 CSS 选择器跨越 shadow-dom 边界。这是无效的。
-
由于我只有 4 周的开发时间,我真的不明白你的答案。你能把它详细说明一下,像我这样的新手。 (对不起)
-
nav ul li a:hover + .svg-container .symbol 部分引用符号,部分引用符号的父项,你不能这样做并让它工作。
-
所以我应该只引用符号?
-
可能还有其他问题,里面好像有很多东西,也许你可以进一步减少它。
标签: animation svg geometry hover