javascript - 悬停时将状态重置为原始状态

标签 javascript jquery html css

我有这样的东西:

 $(".leftCues").hover(
        function(){
                $(".item1", ".item2", ".item3", ".item4", ".item5").stop(true,true)
                $(".item1").animate({opacity:1.0}, 2000, function()  {
                  $(".item1").animate({opacity:0.0},2000, function() {
                    $(".item2").animate({opacity:1.0},2000, function()  {
                      $(".item2").animate({opacity:0.0}, 2000, function() {
                        $(".item3").animate({opacity:1.0}, 2000, function()  {
                          $(".item3").animate({opacity:0.0}, 2000, function() {
                            $(".item4").animate({opacity:1.0},2000, function()  {
                              $(".item4").animate({opacity:0.0}, 2000, function() {
                                $(".item5").animate({opacity:1.0}, 2000, function()  {
                                });
                              });
                            });
                          });
                        });
                      });
                    });
                  });
                });
        },
        function(){
                $(".item5").css('opacity', 0.0);
        }       
  );    

CSS:

.item5, .item3, .item1 {
  clear: both;
  float:left;
  margin-top: 6%;
  color: #999999;
  font-size: 40px;
  margin-left: 25px;
  opacity:0.0;
}

.item2, .item4 {
  clear: both;
  float:right;
  margin-top: 6%;
  color: #999999;
  font-size: 40px;
  margin-right: 25px;
  opacity:0.0;
}

当我悬停时我的动画效果很好,但当我悬停时,我以前的状态没有被重置。现在当再次悬停时,一个新的动画开始,而前一个动画仍在运行。

如何重置之前的悬停状态?悬停时,我想回到原始状态(就像我第一次悬停之前一样)

在我的动画中,我只是将不透明度从 1.0 切换到 0.0,我的 css 以不透明度 0.0 开始。

请帮忙。

最佳答案

如果没有其他动画,您可以使用 .fadeIn()fadeOut()

类似这样的东西

$('#item').hover( function() {
      $('#item2, #item3, #item4, #item5').stop(true, true).fadeIn();
  },
  function () {
    $('#item2, #item3, #item4, #item5').stop(true, true).fadeOut();
  }
);

.stop(true, true) 很重要,因为它使它在动画结束时跳转。 Here's the documentation .

关于javascript - 悬停时将状态重置为原始状态,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/14972990/

相关文章:

javascript - ajax 返回负载而不是表单数据

jquery - Ajax 安全?

css - Html <div> 元素背景图像不显示,div 内也没有任何内容

javascript - 如何清除文件输入而不丢失事件监听器和扩展属性?

jquery - 侧面滑出菜单 - 潜在的视口(viewport)/溢出问题

javascript - Chrome 扩展 : Open html in the crx file with no icon on tab

javascript - react 文本区域值控制台警告

javascript - AngularJS:如何将常量对象绑定(bind)到指令

jquery - 使用 jQuery 更快/更高效的实时搜索?

javascript - ajax调用并附加,无法选择附加内容或执行任何操作