简体   繁体   English

如何使用JQuery及时旋转图像?

[英]How would i timely rotate an image with JQuery?

I have an image which when the page is loaded, it slides in the page out of margin to the center of the screen. 我有一个图像,当页面加载时,它在页面中滑出边距到屏幕的中心。 Its a rectangular image in a vertical Position. 它是一个垂直位置的矩形图像。

Here is the code for what its doing: 这是它的作用的代码:

$(document).ready(function() {
    $("#IMAGE").animate({left: "+=810"}, 1135);
});

So as it slides in and is centered, i would like the image to tilt horizontally at 180 degrees right. 因此,当它滑入并居中时,我希望图像水平倾斜180度。 3 seconds after it centered in the middle of the screen. 在屏幕中间居中3秒后。

How Would i do this? 我该怎么做? i tried something similar found here but it didnt work. 我尝试了类似的东西,但它没有用。 Here is what i've attempted but did NOT work. 这是我尝试但没有奏效的。 Correct me if i am wrong in the way i did this but its how i thought it would work and why couldnt it work this way :) 纠正我,如果我做错了,但我认为它会如何工作,为什么它不能这样工作:)

How i attempted: 我是怎么尝试的:

var rotation = function() {
    $("img").rotate({
        angle: 0,
        animateTo: 180,
        callback: rotation
    });
}

$(document).ready(function() {

    $("#IMAGE").animate({left: "+=810"}, 1135);
    /*I PUT THE FUNCTION HERE THINKING IT WOULD CALL IT AFTER CENTERING IT*/
    rotation();
});

Anyway to accomplish this 3 seconds after it centers where it can tilt 180 degrees? 无论如何要在它可以倾斜180度的中心后3秒完成这个?

placing your rotate in a function call as the animate completes will work. 在动画完成时将旋转放置在函数调用中将起作用。 Just place a delay(3000) to get the 3 seconds before it happens. 只需放置一个延迟(3000)即可获得3秒钟。

var rotation = function() {
    $("img").rotate({
        angle: 0,
        animateTo: 180,
        callback: rotation
    });
}


$("#IMAGE").animate({left: "+=210"}, 1135, function(){
     $(this).delay(3000).rotate({
        angle: 0,
        animateTo: 180,
        callback: rotation
    });
});

jsfiddle 的jsfiddle

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

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