0

first of all i'm pretty new with JS. I'm buillding a website and it has a intro. This intro animation have to be placed in a different page and after it ends then the next webpage will be automatically loaded.

<body onload="setTimeout(
function(){
    window.location.href = 'file:///C:/Users/skatto/Desktop/art%20contest/art_contest_page.html';
}, 32000 )">

this is the script i'm using on my html file to automatically load the next page, but it's pretty 'sharp' and rough, how could I add a fade animation? To make it smoother

Alexander Ciesielski
  • 10,506
  • 5
  • 45
  • 66

2 Answers2

0

A simple CSS can do this. why use scripts? Add the animation fadeIn to any body of page you want to fade in before load.

body {
  animation: fadeIn 0.5s linear;
}
@keyframes fadeIn {
  0% {
    opacity: 0;
  }
  100% {
    opacity: 1;
  }
}
<div>
  Something
  <br/>Something
  <br/>Something
  <br/>Something
  <br/>Something
  <br/>Something
  <br/>Something
  <br/>Something
  <br/>Something
  <br/>Something
  <br/>Something
  <br/>Something
  <br/>Something
  <br/>Something
  <br/>Something
  <br/>Something
  <br/>
</div>
Jones Joseph
  • 4,703
  • 3
  • 22
  • 40
0

Try like this

on page 1:

<a href="otherPage.html" class="transition">LINK</a>

$(document).ready(function() {
    $("body").css("display", "none");

    $("body").fadeIn(2000);

    $("a.transition").click(function(event){
        event.preventDefault();
        linkLocation = this.href;
        $("body").fadeOut(1000, redirectPage);      
    });

    function redirectPage() {
        window.location = linkLocation;
    }
});
RAj
  • 71
  • 2
  • 7