var
that;
var
deltaX = 0;
var
minValue = 1;
var
app = getApp();Page({
data: {
value: 0,
canvasHeight: 80 },
onLoad:
function
(options) {
that =
this
;
that.drawRuler();
that.drawCursor(); },
drawRuler:
function
() {
that.setData({
canvasWidth: canvasWidth,
scrollLeft: (currentValue - minValue) * ratio });
context.beginPath();
context.moveTo(origion.x + (i - minValue) * ratio, origion.y);
context.lineTo(origion.x + (i - minValue) * ratio, origion.y - (i % ratio == 0 ? heightDecimal : heightDigit));
context.setLineWidth(2);
context.setStrokeStyle(i % ratio == 0 ? &
#39;gray' : 'darkgray'); // 描线
context.stroke();
context.setFillStyle(&
#39;gray'); if (i % ratio == 0) {
context.setFontSize(fontSize);
context.fillText(i == 0 ? &
#39; ' + i : i, origion.x + (i - minValue) * ratio - fontSize / 2, fontSize); }
context.closePath(); }
context.draw(); },
drawCursor:
function
() {
// 定义三角形顶点 TODO x
var
center = {x: app.screenWidth / 2, y: 5}; // 定义三角形边长
var
length = 20; // 左端点
var
left = {x: center.x - length / 2, y: center.y + length / 2 * Math.sqrt(3)}; // 右端点
var
right = {x: center.x + length / 2, y: center.y + length / 2 * Math.sqrt(3)}; // 初始化context const context = wx.createCanvasContext(&
#39;canvas-cursor');
context.moveTo(center.x, center.y);
context.lineTo(left.x, left.y);
context.lineTo(right.x, right.y);
context.setFillStyle(&
#39;#48c23d');
context.fill();
context.draw(); },
bindscroll:
function
(e) {
deltaX += e.detail.deltaX;
that.setData({
value: Math.floor(- deltaX / 10 + minValue) });
console.log(deltaX) }});