【问题标题】:How to make exactly this circle of progress? (It's compatible with Internet Explorer 9 and times are accurate)如何准确地完成这个循环? (兼容Internet Explorer 9,时间准确)
【发布时间】:2014-02-18 00:24:26
【问题描述】:

我想做一个这样的进度滑块:http://www.elotrolado.net/

我已经尝试过形成进步的循环。但即使它在 Chrome 中运行,Internet Explorer 10 不是在 4 秒内完成,而是在 7 秒内结束。并且 IE9 不可见。

我的密码: http://jsfiddle.net/r6N2X/1/

在之前的网站中,两者都有效。

CSS:

    body {
    margin: 10px;
    padding: 10px;
}
#sl-progress {
    position: absolute;
    z-index: 1;
}

HTML:

<canvas id="sl-progress" width="35" height="35"></canvas>

javascript:

window.requestAnimSpinner = (function () {
    return window.requestAnimationFrame || window.webkitRequestAnimationFrame || window.mozRequestAnimationFrame || window.oRequestAnimationFrame || window.msRequestAnimationFrame;
})
();

var paused = false;
var finished = false;
var endPercent = 100;
var radius = 11;
var curPerc = 0;
var circ = Math.PI * 2;
var quart = Math.PI / 2;
var timeMilli = 4000; // tiempo total
var time = timeMilli / 100;

function animate() {
    var canvas = document.getElementById('sl-progress');
    var x = canvas.width / 2;
    var y = canvas.height / 2;
    var context = canvas.getContext('2d');
    context.lineWidth = 7;
    context.strokeStyle = "#000";

    function render(current) {
        context.clearRect(0, 0, canvas.width, canvas.height);
        context.beginPath();
        context.arc(x, y, radius, -(quart), ((circ) * current) - quart, false);
        context.stroke();
        curPerc++;
        if (curPerc <= endPercent && !paused) {
            setTimeout(function () {
                requestAnimSpinner(function () {
                    render(curPerc / 100);
                });
            }, time);
        } else if (paused) {

        } else {
            //curPerc = 0;
            //context.clearRect(0, 0, canvas.width, canvas.height);
        }
    }
    render();
}

/* START ANIMATION */
 animate();

【问题讨论】:

    标签: javascript html internet-explorer canvas html5-canvas


    【解决方案1】:

    IE9 不支持 requestAnimationFrame。

    但是,您可以使用 Paul Irish 的 polyfill 在 IE9 中进行定时绘制:

    https://gist.github.com/paulirish/1579671

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2012-03-07
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多