かいとうがつきませんね。
jQuery をつかっていません。
ふりはばは、[[x,y],[x1,y1],......]のように 相対的な座標をしてい します
さゆうにも、えんけいにも、うごけます
ぜんかくくうはくは、はんかくにおきかえてください
<!DOCTYPE html>
<title></title>
<meta charset="UTF-8">
<body>
<div id="hoge">
<p>test</p>
<img src="" alt="" id="g0">
<img src="" alt="" id="g1">
<img src="" alt="" id="g2">
<img src="" alt="" id="g3">
</div>
<script>
(function () {
var DEFAULT_OFFSET_POSITION = [[0,0], [2,1], [4,3], [2,1], [0,0], [-2,1], [-4,3], [-2,1]];
function getPosition (e) {
for (var x = 0, y = 0; e; e = e.offsetParent)
x += e.offsetLeft, y += e.offsetTop;
if ('undefined' === typeof this.x) this.x = x;
if ('undefined' === typeof this.y) this.y = y;
return this;
}
function Dancer (target, offsetAryPoint, interval, position) {
this.target = target;
this.point = offsetAryPoint;
this.interval = interval;
this.position = position;
this.timerId = null;
this.index = 0;
this.max = offsetAryPoint.length;
}
function LOOP () {
var n = this.index;
var s = this.target.style;
s.top = this.position.y + this.point[n][1] + 'px';
s.left = this.position.x + this.point[n][0] + 'px';
this.index = (n + 1) % this.max;
}
function start () {
var that = this;
if (! this.timerId)
this.timerId = setInterval (function () { LOOP.call (that) }, this.interval);
return this;
}
function stop () {
clearInterval (this.timerId);
this.timerId = null;
return this;
}
function create (target, offsetAryPoint, interval, position) {
if (1 > arguments.length)
throw new Error;
var p = getPosition.call (position || { }, target);
var s = target.style;
s.position = 'absolute';
s.top = p.y + 'px';
s.left = p.x + 'px';
var obj = new Dancer (
target,
offsetAryPoint || DEFAULT_OFFSET_POSITION,
interval || 50,
p
);
return obj.start ();
}
Dancer.prototype.start = start;
Dancer.prototype.stop = stop;
Dancer.create = create;
this.Dancer = Dancer;
}) ();
var src = 'data:image/gif;base64,' +
'R0lGODlhGAAYALMAAPr4+wBlAQaPARF9CSylD0K9Gk3OHlqzNFnSG23WMHa/TKHfXa3lbczs' +
'ocDpgf///yH5BAEAAA8ALAAAAAAYABgAAATZ8Mkpg72Wah3GWYzjMMsxBBtlKU7jvq6jZFvH' +
'wPjLnNzQxoyg8Ndw8CaBW4O0aDqdPwaqoig+r02GAFFozCSDJfaqBZgPjcEjcHCMn2UzQNA4' +
'WJhvkEAOaAhAdyAMH1h7cn4kUgNMewIGCJAIhmZ+BYkDiwuTW5CTfQIFCAkgmAwJngIEnpWR' +
'CTsDCVyefJ+hkQYJmLaqtJSgkZEFagQIj7x8lQbKywgEYMsGBZPJ0MtqEgTQ0p/V0M4TBMTQ' +
'Ao7dxt/g2ebd4Snh697o7gQF3QXtKRvh+/v5EQA7';
var imgs = document.getElementById ('hoge').getElementsByTagName ('img');
imgs[0].src = imgs[1].src = imgs[2].src = imgs[3].src = src;
var circle = (function (r, n) {
for (var a = [], i = 0; i < n * 2; i++)
a[i]=[Math.sin (i * Math.PI / n) * r |0, Math.cos (i * Math.PI / n) * r];
return a;
}) (50, 60);
Dancer.create (imgs[3], circle, 30, {x:300, y: 200});
Dancer.create (imgs[2], [[0,1], [0,2], [0,4], [0,6], [0,4], [0,2], [0,1], [0,0]], 50);
Dancer.create (imgs[1], [[0,1], [0,2], [0,4], [0,6], [0,4], [0,2], [0,1], [0,0]], 100);
Dancer.create (imgs[0]);
</script>
お礼
babu_baboo様 回答ありがとうございます。 お礼が遅くなってしまい申し訳ありません。 すすすすごいです!!!! 正直にいうと、半分くらい書いてもらったコードが理解出来ていないのですが こまかく調整できて、まさに自分がやりたいことでした。 ありがとうございました!