长按保存图片,或点击按钮保存
程序员文章站
2022-03-29 20:17:09
$("#savebtn").on({ touchstart: function (e) { // 长按事件触发 timeOutEvent = setTimeout(function () { timeOutEvent = 0; save(); ... ......
$("#savebtn").on({ touchstart: function (e) { // 长按事件触发 timeoutevent = settimeout(function () { timeoutevent = 0; save(); }, 400); //长按400毫秒 // e.preventdefault(); }, touchmove: function () { cleartimeout(timeoutevent); timeoutevent = 0; }, touchend: function () { cleartimeout(timeoutevent); if (timeoutevent != 0) { } return false; } }) function save() {
$.ajax({ url: '****', type: 'post', data: { typecode: typecode }, contenttype: 'application/json', success: function (data) { var a = $("<a></a>").attr("href", "data:image/png;base64," + data.data.image).attr("download", "***.png").appendto("body"); a[0].click(); a.remove(); } }); }