jquery配合animated制作载入载出动画效果

2017-08-05  本文已影响0人  xiaoaiai
<!DOCTYPE html>
<html>

    <head>
        <meta charset="UTF-8">
        <meta name="viewport" content="width=device-width,initial-scale=1,minimum-scale=1,maximum-scale=1,user-scalable=no" />
        <title></title>
        <link rel="stylesheet" type="text/css" href="css/animate.css" />
        <script src="js/jquery.min.js" type="text/javascript" charset="utf-8"></script>
    </head>

    <body>
        <button id="btn">btn</button>
        <hr />
        <div id="box" class="animated" data-toggle="true">wellcome</div>
        <script type="text/javascript">
            $('#btn').on('click', function() {
                animateCss('#box', 'zoomIn', 'zoomOut')
            })

            function animateCss(el, animateIn, animateOut) {
                var toggle = $(el).data('toggle');
                if(toggle == true) {
                    $(el).removeClass(animateIn);
                    $(el).addClass(animateOut);
                    $(el).data('toggle', false);
                } else {
                    $(el).removeClass(animateOut);
                    $(el).addClass(animateIn);
                    $(el).data('toggle', true);
                }
            }
        </script>
    </body>

</html>
上一篇下一篇

猜你喜欢

热点阅读