我正在尝试模仿IOS上的instagram建议组件。当从父容器中移除其中一个元素时,它旁边的下一个兄弟将滑入到位。我有以下实现,但向左滑动(animate / transition:marginLeft是我遇到的麻烦)下面是一些代码和笔的链接。
closeIcon.addEventListener('click', function(event) {
var fadeInterval,
slideInterval,
closeIconParent = event.currentTarget.parentNode,
cardParent = closeIconParent.parentNode,
nextElement = closeIconParent.nextSibling.nextElementSibling;
fadeInterval = setInterval(function() {
if(!closeIconParent.style.opacity && !nextElement.style.marginLeft) {
closeIconParent.style.opacity = 1;
}
if(closeIconParent.style.opacity < 0) {
clearInterval(fadeInterval);
}else {
closeIconParent.style.opacity -= 0.1;
}
}, 100);
setTimeout(function() {
cardParent.removeChild(closeIconParent);
nextElement.classList.add('instagramCard-moveLeft')
}, 800)
})
})
}