Skip to content

JS Plugin: Wait for CSS animations to finish #557

Answered by hirasso
kaspost asked this question in Help
Discussion options

You must be logged in to vote

If using JS Plugin, you'll need to use setTimeout(next, yourTransitionDurationInMilliseconds) to wait for your transitions to finish.

Alternatively, you could hook into swup's lifecycle events directly and alter the styles from there (without using JS Plugin):

const swup = new Swup(options);

/**
 * Sets the style on the main transition element
 */
const adjustStyle = (newStyle = {}) => {
  const el = document.querySelector('.transition-main');
  if (!el) return;
  for( const [property, value] of Object.entries(newStyle)) {
    el.style[property] = value;
  }
}
/**
 * Sets the background to blue for the out-animation
 */
swup.on('transitionStart', () => {
  adjustStyle({
    background: "…

Replies: 1 comment 14 replies

Comment options

You must be logged in to vote
14 replies
@kaspost
Comment options

@kaspost
Comment options

@hirasso
Comment options

@kaspost
Comment options

@hirasso
Comment options

Answer selected by kaspost
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Category
Help
Labels
None yet
3 participants