HQChart小程序教程4-动态控制手势滚动页面

示例效果

在这里插入图片描述

canvas 控制页面滚动属性

根据官方文档,disable-scroll 属性是控制画布手势是否可以滚动页面。
https://developers.weixin.qq.com/miniprogram/dev/component/canvas.html
在这里插入图片描述

步骤

1. 使用变量绑定disable-scroll

<canvas class="historychart"  id='historychart' type="2d"  
    style="height:{{Height}}px; width:{{Width}}px;" disable-scroll="{{DisableScroll}}"
    bindtouchstart='historytouchstart' bindtouchmove='historytouchmove' bindtouchend='historytouchend'>
  </canvas> 
Page(
{
    data:
    {
       ........................
       DisableScroll:false
    }
.......................
})

2. 在手势处理函数中控制是否滚动页面

这里我在手势点击画布的时候,做一个是否开启|关闭滚动页面的逻辑。

//K线图事件
 historytouchstart: function (event) 
 {
     if (this.HistoryChart) 
     {
         this.HistoryChart.OnTouchStart(event);

         if (this.HistoryChart.JSChartContainer && this.HistoryChart.JSChartContainer.CurrentChartDrawPicture)
         {	//画图模式中 禁止滚动页面
             this.setData({ DisableScroll: true}, () => {});
         }
         else
         {
             this.setData({ DisableScroll: false}, () => {});
         }
     }
 },

交流QQ群

如果还有问题可以加交流QQ群, 群号在git首页可以找到。

HQChart代码地址

地址:https://github.com/jones2000/HQChart

相关推荐

  1. 程序页面滚动

    2024-06-07 00:44:02       13 阅读
  2. js 控制页面滚动

    2024-06-07 00:44:02       40 阅读
  3. 程序页面导航

    2024-06-07 00:44:02       6 阅读

最近更新

  1. TCP协议是安全的吗?

    2024-06-07 00:44:02       18 阅读
  2. 阿里云服务器执行yum,一直下载docker-ce-stable失败

    2024-06-07 00:44:02       19 阅读
  3. 【Python教程】压缩PDF文件大小

    2024-06-07 00:44:02       18 阅读
  4. 通过文章id递归查询所有评论(xml)

    2024-06-07 00:44:02       20 阅读

热门阅读

  1. excel 转换MAC地址格式方法

    2024-06-07 00:44:02       9 阅读
  2. 求二叉树第k层结点的个数--c++【做题记录】

    2024-06-07 00:44:02       10 阅读
  3. npm:Node.js包管理器的使用指南

    2024-06-07 00:44:02       7 阅读
  4. 【机器学习】之 kmean算法原理及实现

    2024-06-07 00:44:02       10 阅读
  5. DVWA-CSRF

    DVWA-CSRF

    2024-06-07 00:44:02      8 阅读
  6. 算法学习笔记——对数器

    2024-06-07 00:44:02       8 阅读