0
点赞
收藏
分享

微信扫一扫

jQuery更改css

殇感故事 2022-03-17 阅读 80

 

    <script>
        $(function() {
            // var flag = 0
            // $('div').click(function() {
            //     if (flag == 0) {
            //         $(this).addClass('bg')
            //         flag = 1
            //     } else if (flag == 1) {
            //         $(this).removeClass('bg')
            //         flag = 0
            //     }
            // })
            $('div').click(function() {
                $('div').toggleClass('bg')
            })
        })
    </script>
   <style>
        .nav {
            width: 300px;
            height: 300px;
            background-color: pink;
            transition: all 0.5s;
        }
        
        .bg {
            background-color: red;
            transform: rotate(360deg);
        }
    </style>

注意采用flag去改变,if和else if的效果是不一样的,不能随便替换

举报

相关推荐

0 条评论