简体   繁体   English

将鼠标悬停在一个 div 上以触发另一个 div 中的动画

[英]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-blockdiv

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;
}

展示<div>当悬停在另一个 div 及其子项上时</div><div id="text_translate"><p>我有一个 HTML div,里面有孩子。 我有一个附加到 div 的 jQuery 鼠标悬停事件。 鼠标悬停时,我显示另一个 div,鼠标悬停时,我隐藏它。</p><p> 但是,当我将鼠标悬停在“premiumlink”div 上时,一切正常,但是当我将鼠标移到 div 的一个子项上时,有条件显示的 div 会隐藏,但随后 jQuery 发现父 div 仍在悬停,所以它再次显示它。 然后,如果我将 cursor 移回父 div,则该 div 被隐藏然后再次显示。</p><p> 我怎样才能让鼠标悬停和鼠标悬停适用于所有孩子,而不是这个跳跃的 state?</p><p> 这是我的 HTML</p><pre> &lt;div class="platinumlevel" id="premiumlink"&gt; &lt;h1&gt; &lt;img src="~/Content/Images/colorworld.png" alt="Logo" class="eventimage" /&gt; &lt;a href="@Url.Action("Exhibitor1Attendee", "Home")" class="landing"&gt;Company Name&lt;/a&gt; &lt;/h1&gt; &lt;div id="demopreview" style="display: none;"&gt; I should be displayed when "premiumlink" and all it's children are mouseovered &lt;/div&gt; &lt;/div&gt;</pre><p> JS</p><pre> $("#premiumlink").mouseover(function () { $('#demopreview').show(1000); }).mouseout(function () { $('#demopreview').hide(1000); });</pre></div> - Display <div> when hovering over another div and its children

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 悬停在一个div上会改变另一个div - Hovering over one div changes another's img 在另一个div上悬停时触发悬停效果 - Trigger a hover effect while hovering on another div 将鼠标悬停在 1 个 div 上以更改另一个 div 内容 - Hovering over 1 div to change another divs content 将鼠标悬停在另一个div上时,将其定位到特定div - Target a specific div when hovering over another 将鼠标悬停在一个 div 上时,如何将 class 添加到另一个 div? - How do add a class to another div, when hovering over one div? 将div悬停在将保留内容的另一个Div上 - Hovering a div over another Div where the contents will remain 将鼠标悬停在div上时,如何将一个类添加到另一个div? - When hovering over a div, how to add a class to another div? 展示<div>当悬停在另一个 div 及其子项上时</div><div id="text_translate"><p>我有一个 HTML div,里面有孩子。 我有一个附加到 div 的 jQuery 鼠标悬停事件。 鼠标悬停时,我显示另一个 div,鼠标悬停时,我隐藏它。</p><p> 但是,当我将鼠标悬停在“premiumlink”div 上时,一切正常,但是当我将鼠标移到 div 的一个子项上时,有条件显示的 div 会隐藏,但随后 jQuery 发现父 div 仍在悬停,所以它再次显示它。 然后,如果我将 cursor 移回父 div,则该 div 被隐藏然后再次显示。</p><p> 我怎样才能让鼠标悬停和鼠标悬停适用于所有孩子,而不是这个跳跃的 state?</p><p> 这是我的 HTML</p><pre> &lt;div class="platinumlevel" id="premiumlink"&gt; &lt;h1&gt; &lt;img src="~/Content/Images/colorworld.png" alt="Logo" class="eventimage" /&gt; &lt;a href="@Url.Action("Exhibitor1Attendee", "Home")" class="landing"&gt;Company Name&lt;/a&gt; &lt;/h1&gt; &lt;div id="demopreview" style="display: none;"&gt; I should be displayed when "premiumlink" and all it's children are mouseovered &lt;/div&gt; &lt;/div&gt;</pre><p> JS</p><pre> $("#premiumlink").mouseover(function () { $('#demopreview').show(1000); }).mouseout(function () { $('#demopreview').hide(1000); });</pre></div> - Display <div> when hovering over another div and its children 如何通过使用jQuery将鼠标悬停在另一个div上来滑动一个div? - How to slide a div by hovering over another div with jquery? 将鼠标悬停在另一个div上时如何显示div - How to display a div when hovering over another div
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM