更改旋转动画位置

时间:2014-10-02 10:27:44

标签: javascript jquery html css

我正在尝试实现旋转动画,但我想更改div位置。这是我的代码: -

$(function(){
var el=$('div');
el.animate({ deg: 180 }, {
            duration: 1000,
            step: function (now) {
                el.css({
                    transform: 'rotate(' + now + 'deg)'
                });
            },
            complete: function () {                    
     },
  });
});

Fiddle Demo

我想要这个位置(现在是第一个,但我想要第二个): -

enter image description here

感谢您的支持

2 个答案:

答案 0 :(得分:4)

使用translateY(-100%)

$(function(){
var el=$('div');
 el.animate({ deg: 180 }, {
                duration: 1000,
                step: function (now) {
                    el.css({
                        transform: 'rotate(' + now + 'deg) translateY(-100%)'
                    });
                },
                complete: function () {

         },
   });
});

DEMO

答案 1 :(得分:1)

    $(function(){
    var el=$('div');
var topik = $('div').css('top');
    el.animate({ deg: 180 }, {
                duration: 1000,
                step: function (now) {
                    el.css({
                        transform: 'rotate(' + now + 'deg)',
                        top : topik+'500px',
    });
                },
                complete: function () {                    
         },
      });
    })

不要谢谢我;););)

相关问题