简体   繁体   中英

How to create an orbit of three elements around a logo

I'm a newbie and I'm on my first project:

I have three elements (images) and a logo.

When I click on an image this one and the other two ones should move in an orbit of 360° around the logo (with a low z-index when they go on the back of the logo so they can disappear and then reappear).

Is this possible with jquery and css3?

Hiya 2 demos starts with simple:

1) (using divs) http://jsfiddle.net/ErN8X/2/show & code: http://jsfiddle.net/ErN8X/2/

2) http://jsfiddle.net/qXP7H/show/ and code: http://jsfiddle.net/qXP7H/

Please see here as well: jQuery plugin to make an element orbit another?

For the second demo you can copy paste the code from jsfiddle. rest this should help, have a nice one, and don't forget to accept answer if this helps.! :)

Jquery for simple demo

var angle = 0;     // starting position (degrees)
var distance = 30; // distance of b from a
var speed = 60;    // revolution speed in degrees per second
var rate  = 10;    // refresh rate in ms

function f() {

    var o = $('#a').offset();

    var t = o.top + (distance * Math.sin(angle * Math.PI/180.0));
    var l = o.left+ (distance * Math.cos(angle * Math.PI/180.0));

    $('#b').css({
        top: t,
        left: l
    });
    $('#c').css({
        top: t + 20,
        left: l + 30
    });
    $('#d').css({
        top: t +40,
        left: l +40
    });
    angle += (speed * (rate/1000)) % 360;
}

setInterval(f, rate);
​

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