首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >如何在jQuery中使图标与文本一起悬停

如何在jQuery中使图标与文本一起悬停
EN

Stack Overflow用户
提问于 2017-05-27 00:50:35
回答 1查看 17关注 0票数 0

当我将鼠标悬停在菜单项上时,会弹出带有图标的文本。当我将鼠标悬停在图标上时,它会移动到菜单的顶部。

我如何才能使图标在文本弹出的同时移动到顶部?

HTML

代码语言:javascript
复制
    <div class="container">
    <ul id="menu">
        <li>
            <a href="#">
                <i class="icon_about"></i>
                <span class="title">About</span>
                <span class="description">Learn about us</span>
            </a>
        </li>
        <li>
            <a href="#">
                <i class="icon_work"></i>
                <span class="title">Work</span>
                <span class="description">See our work</span>
            </a>
        </li>
    </ul>
    </div>

jQuery

代码语言:javascript
复制
   $("ul#menu a").hover(function() {
           $(this).stop().animate({
               bottom: '0px'
           }, 1000);
       },
       function() {
           $(this).stop().animate({
               bottom: '-65px'
           }, 1000);
       });

   $("ul#menu a i").hover(function() {
           $(this).stop().animate({
               top: '0px'
           }, 1000);
       },
       function() {
           $(this).stop().animate({
               top: '20px'
           }, 1000);
       });
EN

回答 1

Stack Overflow用户

发布于 2017-05-27 01:22:47

我使用下面的jQuery解决了这个问题:

代码语言:javascript
复制
      $("ul#menu a").hover(function() {
          $(this).stop().animate({
              bottom: '0px'
          }, 1000);
      },
      function() {
          $(this).stop().animate({
              bottom: '-65px'
          }, 1000);
      });

  $("ul#menu a").hover(function() {
          $(this).find("i").stop().animate({
              top: '0px'
          }, 500);
      },
      function() {
          $(this).find("i").stop().animate({
              top: '20px'
          }, 500);
      });
票数 0
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/44206569

复制
相关文章

相似问题

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