用svg實現上傳圖片進度條效果

demo:http://codepen.io/tianzi77/pen/jPXRKo

<!DOCTYPE html>
<html lang="en">

<head>
    <meta charset="UTF-8">
    <title>Document</title>
</head>

<body>
    <svg width="440" height="440">
        <circle cx="220" cy="220" r="170" stroke-width="50" stroke="#f5f89a" fill="none"></circle>
        <circle cx="220" cy="220" r="170" stroke-width="50" stroke="#abcdef" fill="none" transform="matrix(0,-1,1,0,0,440)" stroke-dasharray="0 1069"></circle>
        <p>拖我:
            <input id="range" type="range" min="0" max="100" value="0" style="width:300px;">
        </p>
    </svg>
    <script>
        var range = document.querySelector('#range'),
            circle = document.querySelectorAll('circle')[1];
        range.addEventListener('change', function () {
            var percent = this.value / 100,
                perimeter = Math.PI * 2 * 170;
            circle.setAttribute('stroke-dasharray', perimeter * percent + " " + perimeter * (1 - percent));
        })
    </script>
</body>

</html>
發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章