jQuery animating back to original position

后端 未结 1 1881
有刺的猬
有刺的猬 2021-01-03 04:10

I\'ve got a site i\'m working on that has a few absolutelty positioned divs that I need to resize on clicking, these will then fill the container that the divs are in. The q

相关标签:
1条回答
  • 2021-01-03 04:48

    You can store the position when the page first loads using $.data() and use it later, like this:

    $(".work-item .toggle").each(function() {
      $.data(this, 'position', $(this).parent().position());
    }).toggle(function() {
      $(this).parent().animate({ height: '430', width: '930', top: '0', left: '0' }, 750);
    }, function() {
      var position = $.data(this, 'position');
      $(this).parent().animate({ height: '150', width: '200', top: position.top, left: position.left }, 750);
    });
    

    This stores the .position() for each element's parent just before you bind, then uses that when animating back later.

    0 讨论(0)
提交回复
热议问题