如何避免使用JQuery类选择器?

时间:2015-08-21 18:45:15

标签: jquery animation

我刚开始学习JQuery。

我的代码:

 $(document).ready( function(){
   $('.img').click(function(){
     $('.img').animate({
       opacity: 0.25,
       left: "+=50",
       height: "toggle"
     }, 5000, function(){                                                                                             
               // Animation complete.
   });
  })
});

这里.img是一个图像,我正在做一个动画。但我想要的是我不想指定每个类类型如.img。我在页面上的所有元素(图像,p,边框)都可以通过相同的动画。所以我期待像

这样的东西

$(this).click( function{ $(this).animate(.........

是否有可能通过this这样的内容来指定确切的类?我试过这个,它没有用。

1 个答案:

答案 0 :(得分:3)

$(".img").click(function(){
    $(this).animate( ... );
});