简体   繁体   中英

How to make a div animate in on page load?

notice how when you load squareup.com the form on the left animates in. How do you do a css3 animation like that? Is javascript required to add some class unload?

Thanks

Pure CSS 3 animation would be the best way to go - since it's clean, simple and easy.

However, older browsers wont support pure CSS 3 animation so you might be best off with jQuery for now (untill more people support CSS 3 animations perhaps).

<script>
$(function(){
      // make a basic fadeIn animation
      $("#divId").fadeIn();
});
</script>

Replace #divId with your div id attribute. Don't forget to display: none; the div.

For jQuery animations simply go to http://api.jquery.com/animate/

Actually, after reviewing the source code, that effect appears to be mostly, if not all, CSS3. Here's a snippet of the CSS:

.square-signup-form h1, .square-signup-form .pricing-prop, .square-signup-form p, .square-signup-form .instructions, .square-signup-form .cards-accepted, .cardcase-signup-form h1, .cardcase-signup-form .pricing-prop, .cardcase-signup-form p, .cardcase-signup-form .instructions, .cardcase-signup-form .cards-accepted {
        color: #fff;
        -moz-transition: all 800ms cubic-bezier(0.51, 0.01, 0.37, 0.98);
        -webkit-transition: all 800ms cubic-bezier(0.51, 0.01, 0.37, 0.98);
        -o-transition: all 800ms cubic-bezier(0.51, 0.01, 0.37, 0.98);
        transition: all 800ms cubic-bezier(0.51, 0.01, 0.37, 0.98);
}
.square-scene .square-signup-form {
    -moz-transform: translate(0pt, 0pt);
    opacity: 1;
    z-index: 3;
}
.ie8 .square-scene .square-signup-form {
    display: block;
}

You can view the full CSS at https://d1g145x70srn7h.cloudfront.net/static/db447699c3d01e60cd9b8e1e1c721ce8837f22bd/stylesheets/home.css

Here's a copy that's easier to read: http://pastebin.com/gHTn1YuA

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM