How to create an orbit of three elements around a logo

六月ゝ 毕业季﹏ 提交于 2019-12-11 08:15:46

问题


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?


回答1:


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);
​


来源:https://stackoverflow.com/questions/10294720/how-to-create-an-orbit-of-three-elements-around-a-logo

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!