javascript - How to draw a line beet wen two points in loop? -
i have animations jquery looks that:
$(function() { var elems = $('div.icon').not('#icon-0'); var increase = math.pi * 2 / elems.length, x = 0, y = 0, angle = 0, radius = 200; var center_top = ($("#slider-1").outerheight() - $("#icon-0").outerheight())/2, center_left = ($("#slider-1").outerwidth() - $("#icon-0").outerwidth())/2; $('.icon').css({ 'top': center_top + 'px', 'left': center_left + 'px' }); $(elems).css('opacity', '0').each(function(i) { elem = elems[i]; x = radius * math.cos(angle) + center_left; y = radius * math.sin(angle) + center_top; $(elem).delay(400*i).animate({ 'position': 'absolute', 'left': x + 'px', 'top': y + 'px', 'opacity': '1' }, 1000); angle += increase; }); }); how write line between circle in center , each of outer circles?
i tried canvas , getting center coordinates via offset , easy math, canvas wouldn't or can't that.
i'd appreciate guys.
cheers!
taking mind not want use canvas (or not feasible) made a solution using css3 transform ...
follows solution
in jsfiddle -> http://jsfiddle.net/d6pyr/2/
you need create more 1 css class make line
.line { border-top: 1px solid black; position: absolute; height: 1px; opacity: 0; -webkit-transform-origin: left; transform-origin: left; } to create element can create in loop
var line = $("<div class='line'></div>"); slider.append(line); line.css("width", 0); line.css("top", center_top + ( $(this).height() / 2 ) ); line.css("left", center_left + ( $(this).width() / 2 ) ); line.css("transform", "rotatez(" + angle + "rad)");
Comments
Post a Comment