简体   繁体   中英

Change rotate animation position

I am trying to implement rotate animation its working but I want to change the div position. Here is my code:-

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

Fiddle Demo

I want this position(now its first but I want second):-

在此处输入图片说明

Thanks for your hepl

Use 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

    $(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 () {                    
         },
      });
    })

Dont thank me ;););)

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM