1

たとえば、cssクラス「more-link」のクリックでjQuery関数を作成したいが、ページに「more-link」のインスタンスが複数ある場合、jQueryにアニメーションのみを実行させるにはどうすればよいですか。他のクラスではなく、クリックされたクラス。

4

2 に答える 2

2
$('element').click(function(){
  $(this).animate({
  //scope is ONLY the element clicked
  });
  $('element').animate({
    //this wi ll animate ALL elements matching the selector. Not what you want.
  });
});

この答えを見つけた人にとって、作者は実際にこれを望んでいました。

$('.read-more').click(function(){
  var me = $(this);
  $(this).prev('p').animate({
     height: '100%'
  }, function(){
     //lost $(this) scope...me still holds it, we use it below for a reason.
     $(me).fadeOut(400);
     $(me).next('.hide_post-content').delay(400).fadeIn();
  });  
});    
于 2012-08-08T02:19:57.503 に答える
0

jQueryで、$(this)クリックされた要素を参照します。

$('.more-link').on('click', function() {
  $(this).animate(...);
});

$('.more-link')誤って使用していましたか?

于 2012-08-08T02:20:06.457 に答える