這更是一個問題CSS的適合的圓形進度條。CSS:如何根據屏幕尺寸(移動)
我得到的代碼來創建此link圓形進度條。我也粘貼了下面的代碼。
目前,當我使用的代碼,它創建被固定在適當的位置和大小的圓形進度條。即不隨屏幕尺寸擴大或縮小。
問題: 我怎樣才能更新CSS使得它允許圓形棒的大小和以適合屏幕的大小?因爲圓形條應適合不同的手機屏幕尺寸。
代碼以創建一個循環的進度條(Coffescript)
el = document.getElementById('graph')
# get canvas
options =
percent: el.getAttribute('data-percent')
size: el.getAttribute('data-size') or 220
lineWidth: el.getAttribute('data-line') or 20
rotate: el.getAttribute('data-rotate') or 0
canvas = document.createElement('canvas')
span = document.createElement('span')
span.textContent = options.percent + '%'
if typeof G_vmlCanvasManager != 'undefined'
G_vmlCanvasManager.initElement canvas
ctx = canvas.getContext('2d')
canvas.width = canvas.height = options.size
el.appendChild span
el.appendChild canvas
ctx.translate options.size/2, options.size/2
# change center
ctx.rotate (-1/2 + options.rotate/180) * Math.PI
# rotate -90 deg
#imd = ctx.getImageData(0, 0, 240, 240);
radius = (options.size - (options.lineWidth))/2
drawCircle = (color, lineWidth, percent) ->
percent = Math.min(Math.max(0, percent or 1), 1)
ctx.beginPath()
ctx.arc 0, 0, radius, 0, Math.PI * 2 * percent, false
ctx.strokeStyle = color
ctx.lineCap = 'round'
# butt, round or square
ctx.lineWidth = lineWidth
ctx.stroke()
return
drawCircle '#efefef', options.lineWidth, 100/100
drawCircle '#555555', options.lineWidth, options.percent/100
CSS
.progress_chart {
position:relative;
margin: 80px;
width: 220px; height: 220px;
canvas {
display: block;
position:absolute;
top:0;
left:0;
}
span {
color:#555;
display:block;
line-height:220px;
text-align:center;
width:220px;
font-family:sans-serif;
font-size:40px;
font-weight:100;
margin-left:5px;
}
input {
width: 200px;
}
}
JADE代碼
.progress_chart
#graph.chart(data-percent='14')
您是否嘗試過加入 「最大寬度:80vw」 的.progress_chart? – Jacob