【发布时间】:2018-01-27 22:55:18
【问题描述】:
我的代码有问题。 我想让一个 div 旋转,但是当 div 旋转时,位置与以前不同。
.rotateWindow {
position: absolute;
text-align: center;
margin: 0 auto;
width: 150px;
height: 150px;
left:50%;
top:50%;
transform: translate(-50%, -50%);
line-height: 32px;
border: solid 7px;
border-top: #f8f8ff;
border-radius: 50%;
font-family: 'Lobster', cursive;
color: #f8f8ff;
font-size: 18px;
z-index: -1;
-webkit-animation-name: spin;
-webkit-animation-iteration-count: infinite;
-webkit-animation-timing-function: ease-in-out;
-webkit-animation-duration: 6s;
}
@-webkit-keyframes spin {
from {
-webkit-transform: rotate(0deg);
}
to {
-webkit-transform: rotate(360deg);
}
}
}
没有动画,它位于页面中心,在我添加动画后,它位于其主要位置下方。 我也尝试了一个简单的 jquery 代码,但还是一样。
$(function() {
var $elie = $('.rotateWindow');
rotate(0);
function rotate(degree) {
// For webkit browsers: e.g. Chrome
$elie.css({ WebkitTransform: 'rotate(' + degree + 'deg)'});
// For Mozilla browser: e.g. Firefox
$elie.css({ '-moz-transform': 'rotate(' + degree + 'deg)'});
// Animate rotation with a recursive call
setTimeout(function() { rotate(++degree); },5);
}
});
我该如何解决这个问题以及为什么会出错? 谢谢你的建议。
【问题讨论】:
标签: jquery css animation css-animations center