【问题标题】:jQuery wont work? animate function [closed]jQuery 不会工作?动画功能[关闭]
【发布时间】:2012-11-13 08:05:24
【问题描述】:

你好 stackoverflow

我正在浏览一些 jQuery 教程,因为我想开始 2d 聊天。

我有一个代码应该使一些图像的不透明度为 50%,当鼠标悬停图像时为 100%,但它不起作用?图片是 50%,但不会变为 100%。

我的代码:

$(function(){

    $('#container img').animate({
        "opacity" : .50
    });

    $('#container img').hover(function() {
        $(this).animate({  "opactiy": 1  });
        console.log("Den er nu 100% klar");
    });

});

【问题讨论】:

  • 来吧.... opactiy
  • 另外你需要第二个悬停功能来再次降低不透明度,如果这是你想要的效果......

标签: jquery function jquery-animate


【解决方案1】:

您的悬停语句中有错字:

 $(this).animate({  "opactiy": 1  });

应该是:

 $(this).animate({  "opacity": 1  });

【讨论】:

    【解决方案2】:

    只需在第二个.animate() 中将opactiy 更改为opacity

    $(function(){
    
        $('#container img').animate({
            "opacity" : .50
        });
    
        $('#container img').hover(function() {
            $(this).animate({  "opacity": 1  }); // <-- Right here
            console.log("Den er nu 100% klar");
        });
    
    });​
    

    jsFiddle

    【讨论】:

      【解决方案3】:
      $(function(){
      
          $('#container img').animate({
              opacity : '1'
          });
      
          $('#container img').hover(function() {
              $(this).animate({  opacity:'0.5'  });
      
          },function(){
                  $(this).animate({ opacity:'1'  });
      
          });
      
      });​
      

      JSFIDDLE

      【讨论】:

        猜你喜欢
        • 1970-01-01
        • 1970-01-01
        • 2016-11-10
        • 1970-01-01
        • 2021-12-29
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        相关资源
        最近更新 更多