Skip to content

Instantly share code, notes, and snippets.

@sheedy
Created September 17, 2015 20:30
Show Gist options
  • Save sheedy/8fd8c5e55a86c33d49a2 to your computer and use it in GitHub Desktop.
Save sheedy/8fd8c5e55a86c33d49a2 to your computer and use it in GitHub Desktop.
Create transition effect between pages. Source: https://kasper.io/How-to-create-transition-effect-between-pages/
.form-label {
  font-size: 0.875rem;
  color: #4d4d4d !important;
  font-weight: normal;
}

.animate-in { animation: fadeIn .5s ease-in; }

.animate-out {
  transition: opacity .5s;
  opacity: 0;
}

@-webkit-keyframes fadeIn {
  from { opacity: 0; }
  to { opacity: 1; }
}

@keyframes fadeIn {
  from { opacity: 0; }
  to { opacity: 1; }
}

Next step is to add animate-in on each page to <body> tag and after that, half of work is done - page has a nice fade in effect.

Now we only have to add fade out effect just before page unloads. To do that we need a little of JavaScript:

window.addEventListener("beforeunload", function () {
  document.body.classList.add("animate-out");
});
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment