jQuery:仅为当前div设置动画

时间:2015-12-10 14:51:27

标签: javascript jquery

如何仅为当前div中的元素设置动画?如果用户单击“编辑”,则应仅为当前单击的部分设置动画,而不是所有div。

$('.js-edit').click(function() {
  if ($('.other,.hide-content, .show-content').is(':animated')) return;
  // Hide 'Edit link'
  $(this).fadeOut(200);

  // Push down 'other' div
  $('.other').animate({
    'marginTop': "+=400px" //moves down
  });

  // Hide content
  $('.hide-content').delay(200).fadeOut(200);

  // Show hidden content
  $('.show-content').delay(400).fadeIn(200);
});

$(".js-cancel").click(function() {
  if ($('.other,.hide-content, .show-content').is(':animated')) return;
  $('.js-edit').delay(200).fadeIn(200);
  $('.other').delay(200).animate({
    'marginTop': "-=400px" //moves up
  });
  // Show content
  $('.hide-content').delay(200).fadeIn(200);

  // Hide shown content
  $('.show-content').fadeOut(200);
});

jsFiddle

1 个答案:

答案 0 :(得分:1)

你需要使用

$(this).closest('.section').find

例如$('.hide-content')

$(this).closest('.section').find('.hide-content').....
相关问题