function mooveItem(item, speed, pos, direction) { /* , .. */ if(isNaN(item.ldir)) item.ldir = pos.min; if(isNaN(item.tdir)) item.tdir = pos.min; /* .. , */ if(direction == "h") item.ldir = item.ldir == pos.max ? pos.min : pos.max; if(direction == "v") item.tdir = item.tdir == pos.max ? pos.min : pos.max; /* */ var animation = direction == "v" ? { top : item.tdir } : { left : item.ldir }; /* */ item.animate(animation, { duration : speed, complete : function() { mooveItem(item, speed, pos, direction); }, queue : false // , }); }
function addPlanet() { var bodyw = $("body").innerWidth(); var bodyh = $(window).height(); /* () , ( ) */ var size = Math.floor(Math.random() * 50); var speed = size * 1000; var obj = $("<div>"); obj .addClass("obj") .css("left", bodyw / 2) .css("top", bodyh / 2) .css("width", size) .css("height", size); /* */ /* , 10 */ mooveItem(obj, speed, { min: size * 10, max: bodyw - size * 10 }, "h"); /* 2/4 3/4 */ mooveItem(obj, speed, { min: bodyh / 2 - 100, max: bodyh / 2 + 100 }, "v"); $("body").append(obj); }
body { background: #000; } .obj { border-radius: 50%; opacity: 1; box-shadow: 0px 0px 15px #fff; border-radius: 50%; position: absolute; background: #fff; }
$(window).load(function() { /* 100, */ for(i=1; i<100; i++) addPlanet(); });
Source: https://habr.com/ru/post/202858/
All Articles