在悬停时在jquery中添加类

时间:2014-08-16 20:56:23

标签: jquery

On Hover我正在尝试添加一个类并更改图像,但我的图像仍然悬停在静止状态。 fiddle

  $( "img.animation" ).hover(
  function() {
    $( this )
      .attr('src', "https://raw.githubusercontent.com/thoughtbot/refills/master/source/images/placeholder_logo_2.png")
      .addClass("animated fadeInDown");
    }, function() {
    $( this )
      .attr('src', "https://raw.githubusercontent.com/thoughtbot/refills/master/source/images/placeholder_logo_1.png")
      .removeClass("animated fadeInDown").animate("slow");
    }
);

2 个答案:

答案 0 :(得分:2)

变化:

img.animation

要:

image_animation

您没有任何名为img.animation的课程。

<强> JSFiddle Demo

答案 1 :(得分:1)

您没有img.animation

这样看起来很棒:

$(document).ready(function(){
//http://api.jquery.com/hover/

    //changing logo
  $( ".grid-item" ).hover(
  function() {
    $( this )
      .find('img')
      .attr('src', "https://raw.githubusercontent.com/thoughtbot/refills/master/source/images/placeholder_logo_2.png")
      .addClass("animated fadeInDown");
    }, function() {
        //than slide it up
    $( this )
      .find('img')
      .attr('src', "https://raw.githubusercontent.com/thoughtbot/refills/master/source/images/placeholder_logo_1.png")
      .removeClass("animated fadeInDown")
      .animate("slow");
    }
);

});//docu.ready