在html里怎么添加控件上图片一直按顺时针旋转旋转

在html里怎么添加控件上图片一直按顺时针旋转旋转,第1张

CSS3 允许您使用 3D 转换来对元素进行格式化。

在本章中,您将学到其中的一些 3D 转换方法:

rotateX()

rotateY()

点击下面的元素,来查看 2D 转换与 3D 转换之间的不同之处:

2D 旋转

3D 旋转

它如何工作?

转换是使元素改变形状、尺寸和位置的一种效果。

您可以使用 2D 或 3D 转换来转换您的元素。

实例

div

{

transform: rotateX(120deg)

-webkit-transform: rotateX(120deg) /* Safari 和 Chrome */-moz-transform: rotateX(120deg) /* Firefox */}

一定要用canvas吗?这里给你一个代码,看看能不能参考一下,有必要你模仿着改成canvas咯。

上代码(图片自己找一张):

<html>

<head>

<style>

#rotate_img {

margin: 100px

}

</style>

</head>

<body>

<button onclick="rotate()">开始旋转</button>

<button onclick="pause()">暂停旋转</button>

<!--这里自己找张图片,路径写对就行-->

<img src='photo.jpg' id='rotate_img'/>

</body>

</html>

<script>

<!--

var x, n=0, rotINT

function rotate() {

x = document.getElementById("rotate_img")

clearInterval(rotINT)

rotINT = setInterval("startRotate()",10)

}

function pause () {

clearInterval(rotINT)

}

function startRotate() {

n = n + 1

x.style.transform = "rotate(" + n + "deg)"

x.style.webkitTransform = "rotate(" + n + "deg)"

x.style.OTransform = "rotate(" + n + "deg)"

x.style.MozTransform = "rotate(" + n + "deg)"

if (n == 180 || n == 360) {

if (n >= 360){

n = 0

}

}

}

//-->

</script>

<!DOCTYPE HTML>    

<html>    

<head>    

   <meta charset=UTF-8>    

   <title>YuGiOh</title>    

   <style type="text/css">    

    *{    

    margin:0    

    padding:0

    

    }    

       #div {    

   position: absolute    

   top: 50px    

   left: 300px    

   width: 300px    

   height: 300px    

   line-height: 300px    

   text-align: center    

   border: 1px solid black    

   border-radius: 160px    

}    

   </style>    

   <script type="text/javascript">    

       var deg = 0    

       var rotateHTML5 = function(limit) {    

           deg += limit    

           deg = deg > 360 ? 1 : deg    

           div.style['transform'] = div.style['-webkit-transform'] = 'rotate(' + deg + 'deg)'    

       }    

       var rotateIE = function(obj) {    

           var d = !! obj.d ? obj.d : 1    

           var r = d * Math.PI / 180    

           costheta = Math.cos(r)    

           sintheta = Math.sin(r)    

           obj.style.filter = "progid:DXImageTransform.Microsoft.Matrix()"    

           var item = obj.filters.item(0)    

           var width = obj.clientWidth    

           var height = obj.clientHeight    

           item.DX = -width / 2 * costheta + height / 2 * sintheta + width / 2    

           item.DY = -width / 2 * sintheta - height / 2 * costheta + height / 2    

           item.M11 = costheta    

           item.M12 = -sintheta    

           item.M21 = sintheta    

           item.M22 = costheta    

           obj.timer = setTimeout(function() {    

               var dx = d + 1    

               dx = dx > 360 ? 1 : dx    

               obj.d = dx    

               rotateIE(obj)    

           }, 30)    

       }    

       var start = function() {    

           if (!/.*MSIE.*/i.test(navigator.userAgent)) {    

               if ( !! div.interval) {    

                   clearInterval(div.interval)    

                   div.interval = null    

               } else {    

                   div.interval = setInterval(function() {    

                       rotateHTML5(1)    

                   }, 30)    

               }    

           } else {    

               if ( !! div.timer) {    

                   clearTimeout(div.timer)    

                   div.timer = null    

               } else {    

                   rotateIE(div)    

               }    

           }    

       }    

   </script>    

</head>    

<body>    

   <button onclick="start()">rotate</button>    

   <div id="div">ROTATE</div>    

</body>    

</html>    

//--------------------------

var but = $(".but")

but.find(".close").click(function() {

    but.stop().animate({

        left: -parseFloat(but.css("left")) + "px"

    }, 500)

})


欢迎分享,转载请注明来源:内存溢出

原文地址: http://outofmemory.cn/zaji/8371413.html

(0)
打赏 微信扫一扫 微信扫一扫 支付宝扫一扫 支付宝扫一扫
上一篇 2023-04-15
下一篇 2023-04-15

发表评论

登录后才能评论

评论列表(0条)

保存