js实现按下录音上滑取消

//获取按钮控件
var btnElem = document.getElementById("speechInput"); //获取ID
var posStart = 0; //初始化起点坐标
var posEnd = 0; //初始化终点坐标
function initEvent() {
        btnElem.addEventListener("touchstart", function(event) {
            event.preventDefault(); //阻止浏览器默认行为
            posStart = 0;
            posStart = event.touches[0].pageY; //获取起点坐标

            api.startRecord({

            });
        });
        btnElem.addEventListener("touchend", function(event) {
            event.preventDefault();
            posEnd = 0;
            posEnd = event.changedTouches[0].pageY; //获取终点坐标
            if (posStart - posEnd > 20) {
                //alert("Cancel");
            }else{
                  api.stopRecord(function(ret, err) {
                      if (ret) {
                          path = ret.path;
                          var duration = ret.duration;
                          alert(path);
                      }
                  });
            }
        });
};
initEvent();

感谢文章:
https://www.cnblogs.com/richardcastle/p/8297370.html


原文出处:/show_1EF1Sy2D4XBA.html