How to rotate an image using css3 rotate and setinterval?

有些话、适合烂在心里 提交于 2019-12-24 08:25:03

问题


I want to rotate an image using css3 rotate and javascript setinterval. The image should rotate on mouseover. Anyone know how to ?


回答1:


You don't even need JavaScript to do it; just put a transition for transform on the element, and apply the rotation on hover. For example:

div {
    background-color: red;
    height: 100px;
    -webkit-transition: -webkit-transform 0.5s ease-in-out;
       -moz-transition:    -moz-transform 0.5s ease-in-out;
         -o-transition:      -o-transform 0.5s ease-in-out;
            transition:         transform 0.5s ease-in-out;
    width: 100px;
}

div:hover {
    -webkit-transform: rotate(90deg);
       -moz-transform: rotate(90deg);
        -ms-transform: rotate(90deg);
         -o-transform: rotate(90deg);
            transform: rotate(90deg);
}​

Here's a demo.




回答2:


You can use css3 transform property along with browser specific transform property to rotate and specify degree you want to rotate

<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
<style type="text/css"> 
div
{
width:200px;
height:100px;
background-color:yellow;
/* Rotate div */
transform:rotate(7deg);
-ms-transform:rotate(7deg); /* Internet Explorer */
-moz-transform:rotate(7deg); /* Firefox */
-webkit-transform:rotate(7deg); /* Safari and Chrome */
-o-transform:rotate(7deg); /* Opera */
}
</style>
</head>
<body>

<div>Hello</div>

</body>
</html>


来源:https://stackoverflow.com/questions/9862206/how-to-rotate-an-image-using-css3-rotate-and-setinterval

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!