javascript - 变换 rotate() 不适用于 Animate.css

标签 javascript jquery css css-transitions animate.css

transform : rotate() 在没有 animate.css 的情况下工作,但它不适用于 animate.css

代码如下:

HTML

<div id="fresh">FRESH</div>

CSS

#fresh{
    position : absolute;
    background-color : #cf2c2c;
    width: 38px;
    padding-left: 2px;
    color: #ffffff;
    border-radius: 5px;
    -ms-transform: rotate(-37deg);
    -webkit-transform: rotate(-37deg);
    transform: rotate(-37deg);
    right: 113px;
    bottom: 40px;
    font-size: 10px;
    z-index : 9999;
}

jQuery

$(document).ready(function(){
    $('#fresh').addClass("animated tada");
});

编辑

动画不工作但 rotate() 正在工作。意味着两者不能一起工作。

Demo at Fiddle

最佳答案

更新 1

$(document).ready(function(){
    $('#fresh').addClass("animated tada");
});
#fresh{
    position : absolute;
    background-color : #cf2c2c;
    width: 38px;
    padding-left: 2px;
    color: #ffffff;
    border-radius: 5px;
    -ms-transform: rotate(-37deg);
    -webkit-transform: rotate(-37deg);
    transform: rotate(-37deg);
    right: 113px;
    bottom: 40px;
    font-size: 10px;
    z-index : 9999;
}
<link href="https://daneden.github.io/animate.css/animate.min.css" rel="stylesheet"/>
<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script>
<div id="fresh">FRESH</div>

好的,我找到了为什么不起作用。有必要添加正确的 animate.css 文件:https://daneden.github.io/animate.css/animate.min.css

立即尝试。工作正常

更新 2

   $(document).ready(function(){
finish =0;
AnimateRotate("-37");
  
function AnimateRotate(angle) {
// caching the object for performance reasons
var $elem = $('#fresh');

// we use a pseudo object for the animation
// (starts from `0` to `angle`), you can name it as you want
$({deg: 0}).animate({deg: angle}, {
    duration: 500,
    step: function(now) {
        // in the step-callback (that is fired each step of the animation),
        // you can use the `now` paramter which contains the current
        // animation-position (`0` up to `angle`)
        $elem.css({
            transform: 'rotate(' + now + 'deg)'
        });
    },
    complete: function() {
      if(finish!=1)
        $('#fresh').addClass("animated tada");
    }
});
  };
  $('#fresh').one('webkitAnimationEnd mozAnimationEnd MSAnimationEnd oanimationend animationend', function(){
$('#fresh').removeClass();
finish=1;
AnimateRotate("-37");
  });
});
#fresh{
    position : absolute;
    background-color : #cf2c2c;
    width: 38px;
    padding-left: 2px;
    color: #ffffff;
    border-radius: 5px;
    -ms-transform: rotate(-37deg);
    -webkit-transform: rotate(-37deg);
    transform: rotate(-37deg);
    right: 113px;
    bottom: 40px;
    font-size: 10px;
    z-index : 9999;
}
<link href="https://daneden.github.io/animate.css/animate.min.css" rel="stylesheet"/>
<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script>
<div id="fresh">FRESH</div>

关于javascript - 变换 rotate() 不适用于 Animate.css,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/34059565/

相关文章:

javascript - 我如何在 javascript 或 jquery 中按维度对图像进行排序

jQuery 不会添加 CSS,只有在 HTML 已经定义的情况下才会更改 CSS

javascript - 覆盖 twitter bootstrap 文本框发光和阴影

javascript - 如何根据选择框值将 div 复制一定次数?

php - 所选数据库中的表和所选表中的字段

jquery - 为自定义 HTML5 和 jQuery 视频播放器持续显示时间

javascript - 如何在 TinyMCE 中放置不可编辑的标签或 Div,以便它可以随文本滚动?

php - 如何使用 AJAX 加载 PHP 脚本?

javascript - React 组件方法返回空数组

javascript - 在 react 引导表的 header 组中使用过滤器