How to implement item reorder/shuffle animations with Angular's ngFor?

后端 未结 4 1252
悲&欢浪女
悲&欢浪女 2020-12-28 12:02

Vue users are easy to implement such item shuffle animations, see their official docs:

\"shuffle

4条回答
  •  借酒劲吻你
    2020-12-28 12:16

    Once the animated elements are not in the view the animation breaks. I fixed it by editing refreshPosition function:

    refreshPosition(prop: string) {
      this.items.forEach(item => {
        item[prop] = {
          top: item.el.offsetTop,
          left: item.el.offsetLeft
        }
      });
    }
    

    Originally @yurzui used el.getBoundingClientRect() to get the positions but this method returns positions relative to the viewport.

    I changed it so it gets the positions using el.offsetTop and el.offsetLeft which are relative to the first ancestor that isn't positioned 'static'.

提交回复
热议问题