How to rotate an image using css3 rotate and setin

2019-08-10 07:02发布

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

2条回答
女痞
2楼-- · 2019-08-10 07:23

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.

查看更多
啃猪蹄的小仙女
3楼-- · 2019-08-10 07:44

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>
查看更多
登录 后发表回答