【发布时间】:2020-04-16 12:14:12
【问题描述】:
我正在使一个半圆在另一个圆内居中。
我希望它具有响应性,因此浏览器中的更改使元素保持在它们需要的中心位置。
我的想法是在另一个圆圈中将两个半圆形按钮相互叠放。
这是我目前所拥有的。
const dims = {height: '80vh', width: '90vw', radius: '7vw'};
const cent = {x: '50vw', y: '35vh'};
const svg = d3.select('#button-box');
const width = svg.attr('width');
const height = svg.attr('height');
console.log(width)
svg.append('circle')
.attr('r', dims.radius)
.attr('cx', cent.x)
.attr('cy', cent.y)
.attr('fill', '#0000a0')
.attr('stroke', 'green')
const g = svg.append('g')
.attr('transform', `translate(${width /2}), ${height /2}`);
g.append('path')
.attr('d', d3.arc()({
innerRadius: 0,
outerRadius: 100,
startAngle: Math.PI / 2,
endAngle: Math.PI * 3/2
}))
.attr('fill', 'whitesmoke')
<script src="https://d3js.org/d3.v5.js"></script>
<script src="js/jonsIdea.js"></script>
<div class="jonsIdea">
<div class="canvas">
<h1>Please select your businesses</h1>
<svg id='button-box' width="90vw" height="80vh">
</svg>
</div>
</div>
谁能帮我将我的 vh/vw 宽度/高度参数动态转换为像素,以便我可以居中并调整半圆?谢谢
【问题讨论】:
-
你为什么用库来创建圈子?你不认为只使用 css 是可能的吗?
-
我需要使用库来制作半圆。我可以复制并粘贴一个半圆并用 CSS 更改它。你觉得这样行吗?
-
圆形和半圆形(还有许多其他形状)仅使用 css 就非常简单。您可能希望将其视为一种选择。
标签: javascript html css d3.js