用createCanvasContext画一个圆形进度条,真机上就没有反应
发布于 6 年前 作者 sxu 13397 次浏览 来自 问答

我用wx.createCanvasContext 画了两个圆,作用是一个圆形的倒计时进度条,在编辑器上好用,真机(iOS和安卓)上,没有动画效果。

页面代码:

<view class=“wrap”>

<view class=“circle-box”>

<view style=‘positon:relative’>

<canvas class=“circle” style=“width:100px; height:100px;z-index:20;” canvas-id=“canvasArcCir”>

</canvas>

<canvas class=“circle” style=“z-index: 15; width:100px; height:100px;” canvas-id=“canvasCircle”>

</canvas>

<view style=‘position:absolute;right:-128px;top:45px;’>

<text style=“font-size: 28rpx;”>{{singleTime}}</text>

</view>

</view>

</view>

</view>

js代码:

function readyCircle(){

//创建单题时间圆形倒计时框。

var cxt_arc = wx.createCanvasContext(‘canvasCircle’);

cxt_arc.setLineWidth(6);

cxt_arc.setStrokeStyle(’#d81e06’);

cxt_arc.setLineCap(‘round’);

cxt_arc.beginPath();

cxt_arc.arc(60, 60, 26, 0, 2 * Math.PI, false);

cxt_arc.stroke();

cxt_arc.draw();

}

/**

* 倒计时圆圈

*/

function drawCircle(quesTime) {

var ctx = wx.createCanvasContext(‘canvasArcCir’);

console.log(“zouzhe…”)

clearInterval(varName);

function drawArc(s, e) {

ctx.setFillStyle(‘white’);

ctx.clearRect(0, 0, 200, 200);

//ctx.draw();

var x = 60, y = 60, radius = 26;

ctx.setLineWidth(5);

ctx.setStrokeStyle(’#eaeaea’);

ctx.setLineCap(‘round’);

ctx.beginPath();

ctx.arc(x, y, radius, s, e, false);

ctx.stroke()

ctx.draw()

}

var step = 1, startAngle = 1.5 * Math.PI, endAngle = 0;

var animation_interval = 1000, n = quesTime;

var animation = function () {

if (step <= n) {

endAngle = step * 2 * Math.PI / n + 1.5 * Math.PI;

drawArc(startAngle, endAngle);

step++;

} else {

clearInterval(varName);

}

};

varName = setInterval(animation, animation_interval);

}

1 回复

将背景的circle的z-index设为-99

回到顶部