如何创建与使用jQuery不同对象的圆形动画

如何创建与使用jQuery不同对象的圆形动画

本文介绍了如何创建与使用jQuery不同对象的圆形动画的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

如何创建使用不同的对象 JQUERY 的圆形动画。我曾尝试自己,但问题是,我的纸条运行不流畅......你们对此有什么想法,请尽快回复我。

How to create circular animation with different objects using JQUERY. I have tried myself but the issue is that my scrip is not running smoothly ... you guys have any idea about this please reply me asap

我想这个动画,但顺利地

I want this animate but in smooth way

努力
    

HTML code

Html Code

<div id="apDiv1"><p><img src="http://4.bp.blogspot.com/_UkDBPY_EcP4/TUr43iCI-FI/AAAAAAAADR0/o9rAgCt9d-U/s1600/1242796868203109724Number_1_in_green_rounded_square_svg_med.png"  width="200" height="115" id="img-1"/></p></div>
<div id="apDiv2"><p><img src="https://encrypted-tbn0.gstatic.com/images?q=tbn:ANd9GcRZv4hqGcyV6OqP0hI3uAiQVwHHgPuqcTl2NppFRyvbxXLVokbs"  width="200" height="115" id="img-2"/></p></div>
<div id="apDiv3"><p><img src="https://encrypted-tbn2.gstatic.com/images?q=tbn:ANd9GcQaplzZIaF-uTQKnvfK9N9i-Rg27F6aHtSchQZaGR-DITgO1bDwzA"  width="200" height="115" id="img-3"/></p></div>
<div id="apDiv4"><p><img src="https://encrypted-tbn3.gstatic.com/images?q=tbn:ANd9GcQjTbe5WfEnT840gIChKfbzlVnoPPoZsyrT4zjMReym9YpsRdOFvA"  width="200" height="115" id="img-4"/></p></div>
<div id="apDiv5"><p><img src="https://encrypted-tbn3.gstatic.com/images?q=tbn:ANd9GcRWtiMAcxGe-RQw2gRwUUiyB5aRTMeVMG5LSCPF0Qpzes-USpgyTw"  width="200" height="115" id="img-5"/></p></div>
<div id="apDiv6"><p><img src="https://encrypted-tbn0.gstatic.com/images?q=tbn:ANd9GcTXDhOygDcNsNVsv0eIXLYdBx4C-tmedIRhFfxGlCoCfNy04YU_"  width="200" height="115" id="img-6"/></p></div>
<div id="apCenterDiv"><img src="https://encrypted-tbn3.gstatic.com/images?q=tbn:ANd9GcR42cgsKsYMWey79jT0XsTkMOyxc9oej9fVt-udxQvnVFOadpPQ"  width="200" height="115" /></div>

的CSS code

Css Code

<style type="text/css">
#apCenterDiv {
    position:absolute;
    width:200px;
    height:115px;
    z-index:1;
    left: 571px;
    top: 209px;
}
#apDiv1 {
    position:absolute;
    width:200px;
    height:115px;
    z-index:2;
    left: 570px;
    top: 4px;
}
#apDiv2 {
    position:absolute;
    width:200px;
    height:115px;
    z-index:3;
    left: 821px;
    top: 134px;
}
#apDiv3 {
    position:absolute;
    width:200px;
    height:115px;
    z-index:4;
    left: 822px;
    top: 328px;
}
#apDiv4 {
    position:absolute;
    width:200px;
    height:115px;
    z-index:5;
    left: 572px;
    top: 385px;
}
#apDiv5 {
    position:absolute;
    width:200px;
    height:115px;
    z-index:6;
    left: 319px;
    top: 329px;
}
#apDiv6 {
    position:absolute;
    width:200px;
    height:115px;
    z-index:7;
    left: 319px;
    top: 135px;
}
</style>

剧本

<script>
$(document).ready(function(e) {

      setInterval(function() {

        var imgfirstSrc = $("#img-1").attr("src");
        var imgSecSrc = $("#img-2").attr("src");
        var imgthirdSrc = $("#img-3").attr("src");
        var imgfourthSrc = $("#img-4").attr("src");
        var imgfifthSrc = $("#img-5").attr("src");
        var imgsixthSrc = $("#img-6").attr("src");


        $("#img-2").attr("src",imgfirstSrc);
        $("#img-3").attr("src",imgSecSrc);
        $("#img-4").attr("src",imgthirdSrc);
        $("#img-5").attr("src",imgfourthSrc);
        $("#img-6").attr("src",imgfifthSrc);
        $("#img-1").attr("src",imgsixthSrc);



      },1000);
});
</script>

修改

我要与点击/停止事件添加更多的动画。当用户点击270红色图像地方,他们不得不更换的90和动画的地方将被停止..更多的澄清,你必须看到下面的图片...我已经试过 @Cristi仆妇 code,但我希望有更多的修改

I have to add more animation with click/stop events. When user click the red image place of 270 they have to replace the place of 90 and animation will be stop.. for more clarification you have to see the image below... i have tried @Cristi Pufu code but i want more modification

努力
  

推荐答案

使用 jQuery的动画

使用数学的jQuery

使用 CSS3轮换(只是为了好玩):

Using CSS3 Rotation (just for fun): http://jsfiddle.net/dMnKX/

只需添加一个的盒子,以您的动画的div 小提琴和使用本 JS

Just add a class 'box' to your animating divs like in the fiddle and use this js:

$(document).ready(function(e) {

    var animate = function(){

        var boxes = $('.box');

        $.each(boxes, function(idx, val){

            var coords = $(boxes[idx+1]).position() || $(boxes[0]).position();

            $(val).animate({

                "left" : coords.left,
                "top" : coords.top

            }, 1500, function(){})

        });
    }

    animate();

    var timer = setInterval(animate, 2000);
});

修改

$(document).ready(function(e) {
    var angles = [90, 45, 315, 270, 225, 135];
    var unit = 215;

    var animate = function(){

        $.each($('.box'), function(idx, val){

            var rad = angles[idx] * (Math.PI / 180);
            $(val).css({
                left: 550 + Math.cos(rad) * unit + 'px',
                top: unit * (1 - Math.sin(rad))  + 'px'
            });

            angles[idx]--;
        });

    }
    var timer = setInterval(animate, 10);

});

您必须修改离开宽度,盒高度性质,规范他们,设置正确的单元圆半径)和初始角度。但是,对于一个preVIEW,我认为这是你想要的(只是需要更多一点的工作)。

You have to change the left, top, width, height properties of boxes, standardize them, set the correct unit (circle radius) and initial angles. But for a preview, i think this is what you want (just needs a little more work).

例如:

角度的视觉理解:

这篇关于如何创建与使用jQuery不同对象的圆形动画的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

07-24 20:00