반응형
Notice
Recent Posts
Recent Comments
Link
«   2025/05   »
1 2 3
4 5 6 7 8 9 10
11 12 13 14 15 16 17
18 19 20 21 22 23 24
25 26 27 28 29 30 31
Tags
more
Archives
Today
Total
관리 메뉴

비전공개미 개발노트

[JavaScript / jQuery] 클릭할때마다 무한회전 본문

프론트엔드/JavaScript

[JavaScript / jQuery] 클릭할때마다 무한회전

비전공개미 2022. 10. 6. 18:29
반응형
SMALL
<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Document</title>
    <script src="https://code.jquery.com/jquery-3.6.1.js" integrity="sha256-3zlB5s2uwoUzrXK3BT7AX3FyvojsraNFxCc2vC/7pNI=" crossorigin="anonymous"></script>
</head>
<body>
    <!-- <img id="chic" src="../images/aaa.gif" alt="치킨"> -->
    <div id="chic" style="width:200px;height:200px;border:2px solid #aaa;background-color:yellow;text-align:center;line-height:200px;">나 돌아간다~</div>
    <script>
        //deg 90도로 회전시작
        var deg = 90;

        //처음 90값을 넣는다
        function rot(a){
            //css transform: rotate(90deg); 실행
            $("#chic").css("transform", "rotate("+a+"deg)");
            //deg값에 +90을 추가
            deg = deg + 90;
            //deg값이 360을 넘어가면 deg값은 다시 90으로 초기화(안해도 잘 돌아감)
            //if(deg > 360){
            //    deg = 90;
            //}
        }

        //id chic를 클릭하면 rot함수가 실행된다
        $("#chic").click(function(){
            rot(deg);
        });
    </script>
</body>
</html>
Document
나 돌아간다~
반응형
LIST
Comments