Filling the bar?

3

How do I make it when I open the site with this code, it already "fills" this bar and remains filled, without having to keep the mouse over?

div {
    width: 50px;
    height: 50px;
    background: red;
    -webkit-transform: width 2s; /* Safari */
    transition: width 2s;
	border-radius: 100px;
}

/* For Safari 3.1 to 6.0 */
#div1 {-webkit-animation-timing-function: linear;}
#div2 {-webkit-transform-timing-function: ease;}
#div3 {-webkit-transform-timing-function: ease-in;}
#div4 {-webkit-transform-timing-function: ease-out;}
#div5 {-webkit-transform-timing-function: ease-in-out;}

/* Standard syntax */
#div1 {transform-timing-function: linear;}
#div2 {transform-timing-function: ease;}
#div3 {transform-timing-function: ease-in;}
#div4 {transform-timing-function: ease-out;}
#div5 {transform-timing-function: ease-in-out;}

div:hover {
    width: 50%;
}
<body>

<p><b>Note:</b> This example does not work in Internet Explorer 9 and earlier versions.</p>

<div id="div1"></div><br>
<div id="div2"></div><br>
<div id="div3"></div><br>
<div id="div4"></div><br>
<div id="div5"></div><br>

<p>Hover over the div elements above, to see the different speed curves.</p>

</body>
    
asked by anonymous 29.09.2017 / 23:08

1 answer

6

It's quite simple, the trigger responsible for the animation in your code is hover , ie, it will only execute the animation when you mouse-over. To do while the page opens, simply create a keyframe.

I've also added different durations for you to understand better.

div {
    width: 50%;
    height: 50px;
    background: red;
    animation-name: animacao;
    border-radius: 100px;
}

#div1 {
  animation-duration: 2s;
}

#div2 {
  animation-duration: 5s;
}

#div3 {
  animation-duration: 10s;
}

#div4 {
  animation-duration: 15s;
}

#div5 {
  animation-duration: 30s;
}

@keyframes animacao {
    from {width: 50px;}
    to {width: 50%;}
}
<div id="div1"></div><br>
<div id="div2"></div><br>
<div id="div3"></div><br>
<div id="div4"></div><br>
<div id="div5"></div><br>

You can read more about animations here .

    
29.09.2017 / 23:17