2015-04-29 2 views
2

Как подключить номера с пунктирными линиями в нижнем jsfiddle.jQuery connect with lines

Я хочу, чтобы эти строки начинались с границы внутреннего круга, либо из jQuery, либо из css. Я имею в виду, что вокруг границы внутреннего круга начинаются от внутреннего края границы до числа, ....... 1, ..... 2, чтобы показать направляющие линии.

http://jsfiddle.net/ineffablep/x03f61db/

function createFields() { 
    $('.field').remove(); 
    var container = $('#container'); 
    for(var i = 0; i < +$('input:text').val()+1; i++) { 
     $('<div/>', { 
      'class': 'field', 
      'text': i 
     }).appendTo(container); 
    } 
} 

function distributeFields() { 


    var fields = $('.field'), container = $('#container'), 
     width = center.width()*2, height = center.height()*2, 
     angle = 0, step = (2*Math.PI)/fields.length; 
    var radius = width/2; 
    var containerLength=$('input:text').val(); 
    angle=step* (containerLength-1); 

    fields.each(function() { 

     var x = Math.round(width + radius * Math.cos(angle)); 
     var y = Math.round(height + radius * Math.sin(angle)); 
      $(this).css({ 
      right: x + 'px', 
      top: y + 'px' 
     }); 
     angle -= step; 

    }); 
} 
var center = $('#center'); 

$(window).resize(function(height) { 

    $('#container').width($(window).height()*0.9) 
    $('#container').height($(window).height()*0.9) 
    var width = $('#container').width() * 0.4; 
    console.log("width",$('#container').width()); 
    console.log("height",$('#container').height()); 
    var radius = width/2; 
    width += 'px'; 
    radius += 'px'; 
    center.css({ 
     width: width, height: width, 
     '-moz-border-radius' : radius, 
     '-webkit-border-radius' : radius, 
     'border-radius' : radius 
    }); 

createFields(); 
distributeFields(); 
    // rest of your code for font-size setting etc.. 
}); 

$(window).resize(); 


$('input').change(function() { 
    createFields(); 
    distributeFields(); 
}); 

enter image description here

+0

граница означает, с какой стороны границы влево или вправо? – ketan

+0

Я имею в виду вокруг границы начала от края границы до числа, ....... 1, ..... 2, чтобы показать направляющие линии –

+0

@Pangaluri S: Я предложу одно направление, чтобы получить то, что я нашел, когда я googled , пожалуйста, проверьте это, надеюсь, что вы найдете способ: http://stackoverflow.com/questions/11299944/how-to-draw-a-line-using-jquery-and-html5-canvas; http://stackoverflow.com/questions/4576724/dotted-stroke-in-canvas; http://www.rgraph.net/blog/2013/january/html5-canvas-dashed-lines.html#introduction – kiran

ответ

0

Я достиг этого с Canvas

context.fillStyle = '#00867F'; 
    context.fill(); 
    context.lineWidth = 1; 
    context.strokeStyle = '#F0EBF1'; 
    context.stroke(); 

    context.setLineDash([1,2]); 
    context.moveTo(lx, ly); 
    context.lineTo(nx, ny);