Skip to content

Instantly share code, notes, and snippets.

@opr
Created November 8, 2019 12:04
Show Gist options
  • Save opr/c219389a734ee53b9597dfadcb3bd6b4 to your computer and use it in GitHub Desktop.
Save opr/c219389a734ee53b9597dfadcb3bd6b4 to your computer and use it in GitHub Desktop.
import anime from 'animejs';
export const slideDown = (node, displayMode = 'block', easing = 'easeOutExpo', duration = 600) => {
console.log(node);
const nodeToCopy = node.cloneNode(true);
nodeToCopy.style.position = 'absolute';
nodeToCopy.style.display = 'block';
nodeToCopy.style.visibility = 'hidden';
nodeToCopy.style.height = 'auto';
const copiedNode = document.body.appendChild(nodeToCopy);
const heightToSlideTo = copiedNode.getBoundingClientRect().height;
node.style.height = 0;
node.style.display = displayMode;
anime({
targets: node,
height: [0, heightToSlideTo],
duration,
easing
});
copiedNode.remove();
};
export const slideUp = (node, easing = 'easeOutExpo', duration = 600) => {
if (node.getBoundingClientRect().height === 0) {
return;
}
anime({
targets: node,
height: 0,
duration,
easing,
complete() {
node.style.display = 'none';
}
});
};
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment