首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >jQuery/CSS -带有链接的Hover动画

jQuery/CSS -带有链接的Hover动画
EN

Stack Overflow用户
提问于 2016-06-06 12:55:42
回答 3查看 60关注 0票数 0

我有以下jQuery代码:

代码语言:javascript
复制
jQuery('#efficiency-circles .circle').on('mouseenter mouseleave', function(e) {
  if (e.type === "mouseenter") {
    jQuery('h1', this).animate({
      padding: "44px 0 0px 0px",
    }, {
      duration: 300,
      queue: false
    });
    jQuery(this).next().fadeIn();
    jQuery(this).parent().find('.btn').fadeIn();
  } else if (e.type === "mouseleave") {
    jQuery('h1', this).animate({
      padding: "124px 0",
    }, {
      duration: 300,
      queue: false
    });
    jQuery(this).next().fadeOut();
    jQuery(this).parent().find('.btn').fadeOut();
  }
});

代码语言:javascript
复制
<div id="efficiency-circles">

  <span id="top-arrow"></span>
  <span class="circle animated first-pulse full-visible pulse"><h1 style="padding: 124px 0px;">Reduce<br>costs</h1></span>
  <p class="txt-circle-reveal animated">Gain the competitive edge and never miss a sales opportunity.</p>
  <span id="btn-shed" class="btn btn-circle animated">Shed costs</span>

</div>

见JSFIDDLE

基本上,如果你在圆圈上悬停,动画也会像我预期的那样工作,如果我悬停在圆圈内的按钮上,动画就会触发'mouseleave‘函数。

如果我将pointer-events: none;添加到按钮中,它会正常工作,但显然这会停止按钮上的悬停事件和指向外部URL的链接。

如何防止按钮上的悬停事件不触发“mouseleave”事件?

EN

回答 3

Stack Overflow用户

发布于 2016-06-06 13:10:54

您可以选择所有元素的父元素,因此在何处悬停并不重要。

代码语言:javascript
复制
jQuery(document).ready(function($) {
  jQuery('#efficiency-circles').on('mouseenter mouseleave', function(e) {
    if (e.type === "mouseenter") {
      jQuery('h1', this).animate({
        padding: "44px 0 0px 0px",
      }, {
        duration: 300,
        queue: false
      });
      jQuery('.txt-circle-reveal', this).fadeIn();
      jQuery(this).parent().find('.btn').fadeIn();
    } else if (e.type === "mouseleave") {
      jQuery('h1', this).animate({
        padding: "124px 0",
      }, {
        duration: 300,
        queue: false
      });
      jQuery('.txt-circle-reveal', this).fadeOut();
      jQuery(this).parent().find('.btn').fadeOut();
    }
  });
});

我在代码中更改了一些小东西,但在这里工作:小提琴

票数 1
EN

Stack Overflow用户

发布于 2016-06-06 13:11:10

只需将button/span移动到圆圈内,它就可以解决您的问题--,(那个双关语完全没有注意到)。因为在HTML/CSS中,子节点上的hover也会被转换为悬停在父节点上。在HTML/CSS中不存在悬停阻塞的概念。

所以你可以做沿着这条线的东西 (注意:这不是我最骄傲的作品,但应该给你一个漂移;D )。

票数 1
EN

Stack Overflow用户

发布于 2016-06-06 13:03:17

我认为一个可能的解决方案是添加pointer-events: none;并为按钮添加一个onclick选项。

另一种选择是在mouseleave中使用mouseout:https://api.jquery.com/mouseout/

票数 0
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/37658097

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档