2012-10-26 4 views
-1

내가 사업부 상자에 타원에 다른 크기와 DIV의 무리를 마련하기 위해 노력하고 방지 할 수 있습니다.배포 DIV 요소, 중복 및 오버 플로우

http://jsfiddle.net/gz2bH/5/

var stage = $('#stage'); 
$('#middle').css('top', stage.outerHeight()/2 - $('#middle').outerHeight()/2 + 'px'); 
$('#middle').css('left', stage.outerWidth()/2 - $('#middle').outerWidth()/2 + 'px'); 

drawEllipse(".block", stage.outerHeight()/2, stage.outerWidth()/2, stage.outerHeight()/2, stage.outerWidth()/2, 360); 

function drawEllipse(selector, x, y, a, b, angle) { 
var steps = $(selector).length; 

var i = 0; 
var beta = -angle * (Math.PI/180); 
var sinbeta = Math.sin(beta); 
var cosbeta = Math.cos(beta); 

$(selector).each(function(index) { 
    i += (360/steps); 
    var alpha = i * (Math.PI/180); 
    var sinalpha = Math.sin(alpha); 
    var cosalpha = Math.cos(alpha); 
    var X = x + (a * cosalpha * cosbeta - b * sinalpha * sinbeta); 
    var Y = y + (a * cosalpha * sinbeta + b * sinalpha * cosbeta); 


    X = Math.floor(X); 
    Y = Math.floor(Y); 
    if (X > stage.outerHeight()/2) 
     $(this).css('top', X - $(this).outerHeight() + 'px'); 
    else 
     $(this).css('top', X + 'px'); 

    $(this).css('left', Y - $(this).outerWidth()/2 + 'px'); 

}); 

시작점 내가 사업부 년대의 중복과 상자를 넘쳐 방지하려면 어떻게 https://github.com/addyosmani/js-shapelib/blob/master/jquery.shapelib.js

했다 : 여기

내가 아직까지이 무엇인가?

+0

alex23이 : 바이올린은 여기에 있습니다 : 또한 http://jsfiddle.net/gz2bH/5/ – lcase

답변

0

미성년자 및 주요 축 (a와 b) 당신이 달성하려고했던 것에 대해 너무 작았 다. #stage에이 CSS를 사용해보세요.

#stage{ 
width:800px; 
height:600px; 
margin:2em; 
float:left; 
position:relative; 
background:#444; 

}

+0

이 (인해 부정적인 위치에) 몇 가지 요소를 절단하는 것을 방지하기 위해 다음을 수행해야 상자 중심을 페이지 중심으로 오프셋합니다. 당신은 무언가 이렇게 할 수 있습니다. drawEllipse (". block", stage.outerHeight()/2 + 100, stage.outerWidth()/2 + 100, stage.outerHeight()/2, stage.outerWidth()/2, 360); – specialscope

+0

여기에 바이올린이 업데이트되었습니다. http://jsfiddle.net/harendra/bakyN/ – specialscope

+0

감사의 specialscope. 빨간색 상자는 회색 상자 안에 있어야하며 서로 겹치지 않아야합니다. 귀하의 버전에서 그것은 무대의 경계를 넘어서 자랍니다. – lcase