admin管理员组文章数量:1429983
I'm using flexbox to display items in a container- the items snap to their new positions when items are removed/added. Is there anyway to smoothly transition between the states? Transitions between multiple lines is desired and items can be of variable width. I'm using angular JS to add/remove items.
I haven't been able to e up with a working solution. Any ideas?
Plunker here.
I'm using flexbox to display items in a container- the items snap to their new positions when items are removed/added. Is there anyway to smoothly transition between the states? Transitions between multiple lines is desired and items can be of variable width. I'm using angular JS to add/remove items.
I haven't been able to e up with a working solution. Any ideas?
Plunker here.
Share Improve this question edited Mar 17, 2014 at 23:11 bornytm asked Mar 17, 2014 at 23:03 bornytmbornytm 8131 gold badge13 silver badges29 bronze badges2 Answers
Reset to default 2I don't know much about angularJS, but you could do this:
http://jsfiddle/H9mvd/5/
using transitions. To remove an element, first you'd change the width, margins etc. to 0, and then remove the item on the 'transitionEnd' event:
$(this).css({
'margin-left': '0',
'margin-right': '0',
width: '0'
}).on('transitionend', function(){
$(this).remove();
});
And for adding elements, insert the new element with the style attribute such that width, margins etc. are 0. Then remove these from style
so that the element gets transitioned to it's proper size:
container.append('<div style="margin-left:0;margin-right:0;width:0;"></div>');
setTimeout(function(){
// needs placing in a timeout so that
// the CSS change will actually transition
// (CSS changes made right after inserting an
// element into the DOM won't get transitioned)
container.children().last().css({
'margin-left': '',
'margin-right': '',
width: ''
});
},0);
There are 'jumps' in position when adding/removing elements because the flexbox is set with justify-content: space-around;
, so adding/removing an element (even one with zero width) will cause the 'space' between elements to be redistributed. I think it'd be fairly tricky to work around this.
yes, it is, test & try it using animation CSS : http://plnkr.co/edit/VnFTz5VKDJIjFIJ6YBwG?p=preview
div.ng-scope {max-width:15em;overflow:hidden;animation:deploy 2s;}
@keyframes deploy {
from {
max-width:0;
}
to {
max-width:15em;
}
}
本文标签: javascriptIs it possible to animate position of flex items when items are removedaddedStack Overflow
版权声明:本文标题:javascript - Is it possible to animate position of flex items when items are removedadded? - Stack Overflow 内容由网友自发贡献,该文观点仅代表作者本人, 转载请联系作者并注明出处:http://www.betaflare.com/web/1745458671a2659221.html, 本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌抄袭侵权/违法违规的内容,一经查实,本站将立刻删除。
发表评论