js实现图片点击旋转

<!doctype html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <title>Document</title>
    <script>
        window.onload = function(){
            var current = 0;
            document.getElementById('target').onclick = function(){
                current = (current+90)%360;
                this.style.transform = 'rotate('+current+'deg)';
            }
        };
    </script>
</head>
<body>
    <img id ="target" src="img/changepic.jpg" alt="">
</body>
</html>

js实现图片点击旋转_第1张图片
效果是每点击一次,图片会顺时针旋转90度

你可能感兴趣的:(js)