简体   繁体   English

如何使用JQuery旋转图像淡入和淡出

[英]How to rotate an image as it fades In and fades Out with JQuery

I believe this is pretty easy for you, as I have no idea how to integrate what I need into what I already have. 我相信这对您来说很容易,因为我不知道如何将我需要的东西整合到已有的东西中。

Please refer to this fiddle to see what I have: http://jsfiddle.net/pherrera/hnqfLvuk/1/ 请参阅此小提琴以查看我拥有的内容: http : //jsfiddle.net/pherrera/hnqfLvuk/1/

The code: 编码:

 $(document).ready(function () {

 var slowTwinkler = $('.slow');

 //play with the delay time to modify the twinkle order
 $('#star1').delay(5);

 function twinkleSlow() {
     slowTwinkler.animate({ opacity: '+=0.5'}, 1000);
     slowTwinkler.animate({ opacity: '=0.5' }, 3000);
     slowTwinkler.animate({ opacity: '-=0.8'}, 1000, twinkleSlow);
 }

 twinkleSlow();
});

As you can see it fadesIn and fadesOut as I want it, and I'd like to also rotate the image as it appears and disappears. 如您所见,它可以按我的需要逐渐淡入和淡出,并且我还希望在图像出现和消失时也旋转它们。

I found this fiddle where they use this function but I don't know hoe to add it to the code I have. 我在他们使用此功能的地方找到了小提琴 ,但是我不知道要把它添加到我的代码中。 Rotating code: 旋转码:

var rotation = function () {
$("#image").rotate({
    angle: 0,
    animateTo: 360,
    callback: rotation
});
}
rotation();

Any help will be much appreciated. 任何帮助都感激不尽。 Thanks 谢谢

 $(document).ready(function () { var slowTwinkler = $('.slow'); //play with the delay time to modify the twinkle order $('#star1').delay(5); function twinkleSlow() { slowTwinkler.animate({ opacity: '+=0.5'}, 1000); slowTwinkler.animate({ opacity: '=0.5' }, 3000); slowTwinkler.animate({ opacity: '-=0.8'}, 1000, twinkleSlow); } function rotation () { slowTwinkler.animate({ rotation: '+=360'}, 1000); slowTwinkler.animate({ opacity: '=180' }, 3000); } rotation(); twinkleSlow(); }); 

I am not a super expert on JavaScript (so you may need to try some variants) but the above could maybe work? 我不是JavaScript方面的超级专家(因此您可能需要尝试一些变体),但是以上方法可能行得通?

Here you go: 干得好:

$(document).ready(function () {

     var slowTwinkler = $('.slow');

     //play with the delay time to modify the twinkle order
     $('#star1').delay(5);

 function twinkleSlow() {         
     slowTwinkler.animate({ opacity: '+=0.5' , deg: '+=180' }, {
         duration: 1000,
         step: function(now) {
             slowTwinkler.css({
                 '-moz-transform': 'rotate('+now+'deg)',
                 '-webkit-transform': 'rotate('+now+'deg)',
                 '-o-transform': 'rotate('+now+'deg)',
                 '-ms-transform': 'rotate('+now+'deg)',
                 transform: 'rotate('+now+'deg)'
             });
         }
     });
     slowTwinkler.animate({ opacity: '=0.5' }, 3000);
     slowTwinkler.animate({ opacity: '-=0.8', deg: '+=180' }, {
         duration: 1000,
         step: function(now) {
             slowTwinkler.css({
                 '-moz-transform': 'rotate('+now+'deg)',
                 '-webkit-transform': 'rotate('+now+'deg)',
                 '-o-transform': 'rotate('+now+'deg)',
                 '-ms-transform': 'rotate('+now+'deg)',
                 transform: 'rotate('+now+'deg)'
             });
         },
         complete: twinkleSlow
     });
 }

     twinkleSlow();
 });

Link to jsFiddle here . 在此处链接到jsFiddle。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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