Search code examples
htmlcssjquery-animatescaletransition

Scale and fade upon page opening


First issue: I have been trying to get this right but nothing is working. Just as the page is loaded, i want an image to scale and fade down and sit there. The image is also a link.

The code I have so far that works without any animations is

html---

<a href="index.html"> 
    <img src="images/insandoutslogo.jpg" alt="" class="insandoutslogoimg" /> 
    <p1> Ins and Outs </p1>
</a>

css---

.insandoutslogoimg
{
    width: 210px;
    height: 210px;
    position: fixed;
    top: 50%;
    left: 50%;
    margin-top: -112.5px;
    margin-left: -112.5px;
}

THanks heaps!


Solution

  • It's hard to understand the question. But maybe you are looking something like this:

    .insandoutslogoimg {
      width: 210px;
      height: 210px;
      position: fixed;
      top: 50%;
      left: 50%;
      margin-top: -112.5px;
      margin-left: -112.5px;
    
      animation: fadeInDown 2s ease;
    }
    
    @keyframes fadeInDown {
    
      0% {
        transform: scale(0);
        opacity: 0;
      }
    
      100% {
        transform: scale(1);
        opacity: 1;
      }
    }
    

    CodePen demo

    You also need browser prefixes (CodePen uses Lea Verou -prefix-free)