[英]Hovering over one div to trigger animations in another div
This is for my navbar on my personal website.这是我个人网站上的导航栏。 I have my name displayed on the left side of the Navbar.
我的名字显示在导航栏的左侧。 I am trying to make a "wave effect" so that when I hover over my name (made of spans nested in a div), it will trigger the animations of the spans.
我正在尝试制作“波浪效果”,以便当我 hover 覆盖我的名字(由嵌套在 div 中的跨度组成)时,它将触发跨度的动画。 Is there a better approach to this?
有更好的方法吗?
My Navbar now:我现在的导航栏:
Imagine each character going up and back down when I hover across my name.
想象一下,当我 hover 划过我的名字时,每个角色都会上下移动。
Part of React file: React 文件的一部分:
<Navlink to="/" exact={true} className={styles['title-link']}>
<div className={styles.title}>
<span className={styles.animate1}>L</span>
<span className={styles.animate2}>e</span>
<span className={styles.animate3}>e</span>
<span> </span>
<span className={styles.animate4}>R</span>
<span className={styles.animate5}>e</span>
<span className={styles.animate6}>n</span>
<span> </span>
<span className={styles.animate7}>J</span>
<span className={styles.animate8}>i</span>
<span className={styles.animate9}>e</span>
</div>
</Navlink>
Part of SCSS file: SCSS 文件的一部分:
.title-link {
position: relative;
right: 275px;
text-decoration: none;
}
.title {
color: white;
font-family: 'Cedarville Cursive', cursive;
text-decoration: none;
font-size: 30px;
}
.title:hover {
span:first-child {
animation-delay: 0.11s;
}
span:nth-child(2) {
animation-delay: 0.22s;
}
span:nth-child(3) {
animation-delay: 0.33s;
}
span:nth-child(5) {
animation-delay: 0.44s;
}
span:nth-child(6) {
animation-delay: 0.55s;
}
span:nth-child(7) {
animation-delay: 0.66s;
}
span:nth-child(9) {
animation-delay: 0.77s;
}
span:nth-child(10) {
animation-delay: 0.88s;
}
span:nth-child(11) {
animation-delay: 0.99s;
}
}
.animate1, .animate2, .animate3, .animate4, .animate5, .animate6, .animate7, .animate8, .animate9{
animation-name: bounce;
animation-duration: 1s;
}
@keyframes bounce {
0% {
bottom: 0;
}
50% {
bottom: 5px;
}
100% {
bottom: 0;
}
}
I got your example working using css (not scss, counldnt find a fiddle host that allowed scss).我让您的示例使用 css (不是 scss,无法找到允许 scss 的小提琴主机)。
I think the main problem was using spans - they dont appear to animate inline elements.我认为主要问题是使用跨度 - 它们似乎不会为内联元素设置动画。 So I used a
div
with display: inline-block
所以我用了一个带有
display: inline-block
的div
http://jsfiddle.net/vdmpqawj/4/ http://jsfiddle.net/vdmpqawj/4/
<div id="title">
<div class="animate1">L</div>
<div class="animate2">e</div>
<div class="animate3">e</div>
<div class="animate4">R</div>
<div class="animate5">e</div>
<div class="animate6">n</div>
<div class="animate7">J</div>
<div class="animate8">i</div>
<div class="animate9">e</div>
</div>
@-webkit-keyframes bounce {
0%,
100% {
-webkit-transform: translateY(0);
}
50% {
-webkit-transform: translateY(-5px);
}
}
@keyframes bounce {
0%,
100% {
transform: translateY(0);
}
50% {
transform: translateY(-5px);
}
}
#title:hover > div:first-child {
-webkit-animation-name: bounce;
animation-name: bounce;
animation-duration: 1s;
}
#title:hover > div:nth-child(2) {
-webkit-animation-name: bounce;
animation-name: bounce;
animation-duration: 1s;
animation-delay: 0.11s;
}
#title:hover > div:nth-child(3) {
-webkit-animation-name: bounce;
animation-name: bounce;
animation-duration: 1s;
animation-delay: 0.22s;
}
#title:hover > div:nth-child(4) {
-webkit-animation-name: bounce;
animation-name: bounce;
animation-duration: 1s;
animation-delay: 0.33s;
}
#title:hover > div:nth-child(5) {
-webkit-animation-name: bounce;
animation-name: bounce;
animation-duration: 1s;
animation-delay: 0.44s;
}
#title:hover > div:nth-child(6) {
-webkit-animation-name: bounce;
animation-name: bounce;
animation-duration: 1s;
animation-delay: 0.55s;
}
#title:hover > div:nth-child(7) {
-webkit-animation-name: bounce;
animation-name: bounce;
animation-duration: 1s;
animation-delay: 0.66s;
}
#title:hover > div:nth-child(8) {
-webkit-animation-name: bounce;
animation-name: bounce;
animation-duration: 1s;
animation-delay: 0.77s;
}
#title:hover > div:nth-child(9) {
-webkit-animation-name: bounce;
animation-name: bounce;
animation-duration: 1s;
animation-delay: 0.88s;
}
#title {
color: black;
font-family: 'Cedarville Cursive', cursive;
text-decoration: none;
font-size: 30px;
}
#title > div {
display: inline-block;
}
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.