h5手写签名示例

前言

业务中需要用户进行签字,如何让用户在手机端进行签字?
示例如下
在这里插入图片描述
代码已分享至Gitee: https://gitee.com/lengcz/qianming

原示例: https://www.jq22.com/jquery-info13488

H5实现手写签字

创建一个html页面


<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="utf-8">
    <!-- Always force latest IE rendering engine (even in intranet) & Chrome Frame
       Remove this if you use the .htaccess -->
    <meta http-equiv="X-UA-Compatible" content="IE=edge,chrome=1">
    <meta name="viewport" content="initial-scale=1.0, target-densitydpi=device-dpi" /><!-- this is for mobile (Android) Chrome -->
    <meta name="viewport" content="initial-scale=1.0, width=device-height"><!--  mobile Safari, FireFox, Opera Mobile  -->
    <script src="/js/modernizr.js"></script>
    <!--[if lt IE 9]>
    <script type="text/javascript" src="libs/flashcanvas.js"></script>
    <![endif]-->
    <style type="text/css">

        div {
            margin-top:1em;
            margin-bottom:1em;
        }
        input {
            padding: .5em;
            margin: .5em;
        }
        select {
            padding: .5em;
            margin: .5em;
        }

        #signatureparent {
            color:darkblue;
            background-color:darkgrey;
            /*max-width:600px;*/
            padding:20px;
        }

        /*This is the div within which the signature canvas is fitted*/
        #signature {
            border: 2px dotted black;
            background-color:lightgrey;
        }

        /* Drawing the 'gripper' for touch-enabled devices */
        html.touch #content {
            float:left;
            width:92%;
        }
        html.touch #scrollgrabber {
            float:right;
            width:4%;
            margin-right:2%;
            background-image:url(data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAAAEAAAAFCAAAAACh79lDAAAAAXNSR0IArs4c6QAAABJJREFUCB1jmMmQxjCT4T/DfwAPLgOXlrt3IwAAAABJRU5ErkJggg==)
        }
        html.borderradius #scrollgrabber {
            border-radius: 1em;
        }

    </style>
</head>
<body>
<div>
    <div id="content">
        <div id="signatureparent">
            <div>jSignature inherits colors from parent element. Text = Pen color. Background = Background. (This works even when Flash-based Canvas emulation is used.)</div>
            <div id="signature"></div></div>
        <div id="tools"></div>
        <div><p>Display Area:</p><div id="displayarea"></div></div>
    </div>
    <div id="scrollgrabber"></div>
</div>
<script src="/js/jquery-3.2.1.min.js"></script>
<script type="text/javascript">
    jQuery.noConflict()
</script>
<script>
    /*  @preserve
    jQuery pub/sub plugin by Peter Higgins (dante@dojotoolkit.org)
    Loosely based on Dojo publish/subscribe API, limited in scope. Rewritten blindly.
    Original is (c) Dojo Foundation 2004-2010. Released under either AFL or new BSD, see:
    http://dojofoundation.org/license for more information.
    */
    (function($) {
        var topics = {};
        $.publish = function(topic, args) {
            if (topics[topic]) {
                var currentTopic = topics[topic],
                    args = args || {};

                for (var i = 0, j = currentTopic.length; i < j; i++) {
                    currentTopic[i].call($, args);
                }
            }
        };
        $.subscribe = function(topic, callback) {
            if (!topics[topic]) {
                topics[topic] = [];
            }
            topics[topic].push(callback);
            return {
                "topic": topic,
                "callback": callback
            };
        };
        $.unsubscribe = function(handle) {
            var topic = handle.topic;
            if (topics[topic]) {
                var currentTopic = topics[topic];

                for (var i = 0, j = currentTopic.length; i < j; i++) {
                    if (currentTopic[i] === handle.callback) {
                        currentTopic.splice(i, 1);
                    }
                }
            }
        };
    })(jQuery);

</script>
<script src="/js/jSignature.min.noconflict.js"></script>
<script>
    (function($){

        $(document).ready(function() {

            // This is the part where jSignature is initialized.
            var $sigdiv = $("#signature").jSignature({'UndoButton':true})

                // All the code below is just code driving the demo.
                , $tools = $('#tools')
                , $extraarea = $('#displayarea')
                , pubsubprefix = 'jSignature.demo.'

            var export_plugins = $sigdiv.jSignature('listPlugins','export')
                , chops = ['<span><b>提取签名数据: </b></span><select>','<option value="">(select export format)</option>']
                , name
            for(var i in export_plugins){
                if (export_plugins.hasOwnProperty(i)){
                    name = export_plugins[i]
                    chops.push('<option value="' + name + '">' + name + '</option>')
                }
            }
            chops.push('</select><span><b> or: </b></span>')

            $(chops.join('')).bind('change', function(e){
                if (e.target.value !== ''){
                    var data = $sigdiv.jSignature('getData', e.target.value)
                    $.publish(pubsubprefix + 'formatchanged')
                    if (typeof data === 'string'){
                        $('textarea', $tools).val(data)
                    } else if($.isArray(data) && data.length === 2){
                        $('textarea', $tools).val(data.join(','))
                        $.publish(pubsubprefix + data[0], data);
                    } else {
                        try {
                            $('textarea', $tools).val(JSON.stringify(data))
                        } catch (ex) {
                            $('textarea', $tools).val('Not sure how to stringify this, likely binary, format.')
                        }
                    }
                }
            }).appendTo($tools)


            $('<input type="button" value="Reset">').bind('click', function(e){
                $sigdiv.jSignature('reset')
            }).appendTo($tools)

            $('<div><textarea style="width:100%;height:7em;"></textarea></div>').appendTo($tools)

            $.subscribe(pubsubprefix + 'formatchanged', function(){
                $extraarea.html('')
            })

            $.subscribe(pubsubprefix + 'image/svg+xml', function(data) {

                try{
                    var i = new Image()
                    i.src = 'data:' + data[0] + ';base64,' + btoa( data[1] )
                    $(i).appendTo($extraarea)
                } catch (ex) {

                }

                var message = [
                    "If you don't see an image immediately above, it means your browser is unable to display in-line (data-url-formatted) SVG."
                    , "This is NOT an issue with jSignature, as we can export proper SVG document regardless of browser's ability to display it."
                    , "Try this page in a modern browser to see the SVG on the page, or export data as plain SVG, save to disk as text file and view in any SVG-capabale viewer."
                ]
                $( "<div>" + message.join("<br/>") + "</div>" ).appendTo( $extraarea )
            });

            $.subscribe(pubsubprefix + 'image/svg+xml;base64', function(data) {
                var i = new Image()
                i.src = 'data:' + data[0] + ',' + data[1]
                $(i).appendTo($extraarea)

                var message = [
                    "If you don't see an image immediately above, it means your browser is unable to display in-line (data-url-formatted) SVG."
                    , "This is NOT an issue with jSignature, as we can export proper SVG document regardless of browser's ability to display it."
                    , "Try this page in a modern browser to see the SVG on the page, or export data as plain SVG, save to disk as text file and view in any SVG-capabale viewer."
                ]
                $( "<div>" + message.join("<br/>") + "</div>" ).appendTo( $extraarea )
            });

            $.subscribe(pubsubprefix + 'image/png;base64', function(data) {
                var i = new Image()
                i.src = 'data:' + data[0] + ',' + data[1]
                $('<span><b>As you can see, one of the problems of "image" extraction (besides not working on some old Androids, elsewhere) is that it extracts A LOT OF DATA and includes all the decoration that is not part of the signature.</b></span>').appendTo($extraarea)
                $(i).appendTo($extraarea)
            });

            $.subscribe(pubsubprefix + 'image/jsignature;base30', function(data) {
                $('<span><b>This is a vector format not natively render-able by browsers. Format is a compressed "movement coordinates arrays" structure tuned for use server-side. The bonus of this format is its tiny storage footprint and ease of deriving rendering instructions in programmatic, iterative manner.</b></span>').appendTo($extraarea)
            });

            if (Modernizr.touch){
                $('#scrollgrabber').height($('#content').height())
            }

        })

    })(jQuery)
</script>
</body>
</html>

modernizr.js

/* Modernizr 2.5.2 (Custom Build) | MIT & BSD
 * Build: http://www.modernizr.com/download/#-borderradius-csscolumns-canvas-touch-mq-cssclasses-addtest-teststyles-testprop-testallprops-prefixes-domprefixes-fullscreen_api
 */
;window.Modernizr = function(a, b, c) {
    function A(a) {
        j.cssText = a
    }
    function B(a, b) {
        return A(m.join(a + ";") + (b || ""))
    }
    function C(a, b) {
        return typeof a === b
    }
    function D(a, b) {
        return !!~("" + a).indexOf(b)
    }
    function E(a, b) {
        for (var d in a)
            if (j[a[d]] !== c)
                return b == "pfx" ? a[d] : !0;
        return !1
    }
    function F(a, b, d) {
        for (var e in a) {
            var f = b[a[e]];
            if (f !== c)
                return d === !1 ? a[e] : C(f, "function") ? f.bind(d || b) : f
        }
        return !1
    }
    function G(a, b, c) {
        var d = a.charAt(0).toUpperCase() + a.substr(1)
            , e = (a + " " + o.join(d + " ") + d).split(" ");
        return C(b, "string") || C(b, "undefined") ? E(e, b) : (e = (a + " " + p.join(d + " ") + d).split(" "),
            F(e, b, c))
    }
    var d = "2.5.2", e = {}, f = !0, g = b.documentElement, h = "modernizr", i = b.createElement(h), j = i.style, k, l = {}.toString, m = " -webkit- -moz- -o- -ms- ".split(" "), n = "Webkit Moz O ms", o = n.split(" "), p = n.toLowerCase().split(" "), q = {}, r = {}, s = {}, t = [], u = t.slice, v, w = function(a, c, d, e) {
        var f, i, j, k = b.createElement("div"), l = b.body, m = l ? l : b.createElement("body");
        if (parseInt(d, 10))
            while (d--)
                j = b.createElement("div"),
                    j.id = e ? e[d] : h + (d + 1),
                    k.appendChild(j);
        return f = ["&#173;", "<style>", a, "</style>"].join(""),
            k.id = h,
            m.innerHTML += f,
            m.appendChild(k),
        l || g.appendChild(m),
            i = c(k, a),
            l ? k.parentNode.removeChild(k) : m.parentNode.removeChild(m),
            !!i
    }, x = function(b) {
        var c = a.matchMedia || a.msMatchMedia;
        if (c)
            return c(b).matches;
        var d;
        return w("@media " + b + " { #" + h + " { position: absolute; } }", function(b) {
            d = (a.getComputedStyle ? getComputedStyle(b, null) : b.currentStyle)["position"] == "absolute"
        }),
            d
    }, y = {}.hasOwnProperty, z;
    !C(y, "undefined") && !C(y.call, "undefined") ? z = function(a, b) {
            return y.call(a, b)
        }
        : z = function(a, b) {
            return b in a && C(a.constructor.prototype[b], "undefined")
        }
        ,
    Function.prototype.bind || (Function.prototype.bind = function(b) {
            var c = this;
            if (typeof c != "function")
                throw new TypeError;
            var d = u.call(arguments, 1)
                , e = function() {
                if (this instanceof e) {
                    var a = function() {};
                    a.prototype = c.prototype;
                    var f = new a
                        , g = c.apply(f, d.concat(u.call(arguments)));
                    return Object(g) === g ? g : f
                }
                return c.apply(b, d.concat(u.call(arguments)))
            };
            return e
        }
    );
    var H = function(c, d) {
        var f = c.join("")
            , g = d.length;
        w(f, function(c, d) {
            var f = b.styleSheets[b.styleSheets.length - 1]
                , h = f ? f.cssRules && f.cssRules[0] ? f.cssRules[0].cssText : f.cssText || "" : ""
                , i = c.childNodes
                , j = {};
            while (g--)
                j[i[g].id] = i[g];
            e.touch = "ontouchstart"in a || a.DocumentTouch && b instanceof DocumentTouch || (j.touch && j.touch.offsetTop) === 9
        }, g, d)
    }([, ["@media (", m.join("touch-enabled),("), h, ")", "{#touch{top:9px;position:absolute}}"].join("")], [, "touch"]);
    q.canvas = function() {
        var a = b.createElement("canvas");
        return !!a.getContext && !!a.getContext("2d")
    }
        ,
        q.touch = function() {
            return e.touch
        }
        ,
        q.borderradius = function() {
            return G("borderRadius")
        }
        ,
        q.csscolumns = function() {
            return G("columnCount")
        }
    ;
    for (var I in q)
        z(q, I) && (v = I.toLowerCase(),
            e[v] = q[I](),
            t.push((e[v] ? "" : "no-") + v));
    return e.addTest = function(a, b) {
        if (typeof a == "object")
            for (var d in a)
                z(a, d) && e.addTest(d, a[d]);
        else {
            a = a.toLowerCase();
            if (e[a] !== c)
                return e;
            b = typeof b == "function" ? b() : b,
                g.className += " " + (b ? "" : "no-") + a,
                e[a] = b
        }
        return e
    }
        ,
        A(""),
        i = k = null,
        e._version = d,
        e._prefixes = m,
        e._domPrefixes = p,
        e._cssomPrefixes = o,
        e.mq = x,
        e.testProp = function(a) {
            return E([a])
        }
        ,
        e.testAllProps = G,
        e.testStyles = w,
        g.className = g.className.replace(/(^|\s)no-js(\s|$)/, "$1$2") + (f ? " js " + t.join(" ") : ""),
        e
}(this, this.document),
    Modernizr.addTest("fullscreen", function() {
        for (var a = 0; a < Modernizr._domPrefixes.length; a++)
            if (document[Modernizr._domPrefixes[a].toLowerCase() + "CancelFullScreen"])
                return !0;
        return !!document.cancelFullScreen || !1
    });

运行测试用例
在这里插入图片描述

本文来自互联网用户投稿,该文观点仅代表作者本人,不代表本站立场。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如若转载,请注明出处:/a/31737.html

如若内容造成侵权/违法违规/事实不符,请联系我们进行投诉反馈qq邮箱809451989@qq.com,一经查实,立即删除!

相关文章

Wireshark抓包分析(ARP TCP DNS HTTP)

目录 一、ARP 二、DNS 三、TCP TCP的总过程&#xff1a; ​TCP三次握手&#xff1a; TCP四次挥手&#xff1a; 四、HTTP 一、ARP 1.ARP&#xff08;Address Resolution Protocol&#xff09;&#xff0c;是根据IP地址获取物理地址的一个TCP/IP协议。 我们要抓ARP 同网段内…

每日学术速递6.7

CV - 计算机视觉 | ML - 机器学习 | RL - 强化学习 | NLP 自然语言处理 Subjects: cs.CV 1.The ObjectFolder Benchmark: Multisensory Learning with Neural and Real Objects(CVPR 2023) 标题&#xff1a;ObjectFolder 基准测试&#xff1a;使用神经和真实对象进行多感官…

Windows VMware安装RockyLinux9

前言&#xff0c;今天用虚拟机安装rockyLinux时碰到了一些坑&#xff0c;要么时无法联网&#xff0c;要么是无法使用ssh链 接&#xff0c;在这里记录下 准备工作 1. VMware Workstation 17 Pro 2. RockyLinux9.2阿里镜像站&#xff0c;这里无选择了最小版本Rocky-9-latest-x86…

小程序自动化测试的示例代码

背景 近期团队打算做一个小程序自动化测试的工具&#xff0c;期望能够做的业务人员操作一遍小程序后&#xff0c;自动还原之前的操作路径&#xff0c;并且捕获操作过程中发生的异常&#xff0c;以此来判断这次发布时候会影响小程序的基础功能。 上述描述看似简单&#xff0c;但…

【算法证明 七】深入理解深度优先搜索

深度优先搜索包含一个递归&#xff0c;对其进行分析要复杂一些。与上一篇文章一样&#xff0c;还是给节点定义几个状态&#xff0c;然后详细分析深度优先搜索算法有哪些性质。 算法描述 定义状态 v . c o l o r &#xff1a;初始状态为白色&#xff0c;被发现时改为灰色&…

【cfeng work】什么是云原生 Cloud Native

WorkProj 内容管理 云原生云原生应用十二要素应用cfeng的work理解 本文introduce 云原生 Cloud Native相关内容 随着技术的迭代&#xff0c;从最初的物理机—> 虚拟机&#xff0c;从单机 —> 分布式微服务&#xff0c; 现在的热门概念就是云☁&#xff08;cloud&#xff…

python 使用 openpyxl 处理 Excel 教程

目录 前言一、安装openpyxl库二、新建excel及写入单元格1.创建一个xlsx格式的excel文件并保存2.保存成流(stream)3.写入单元格 三、创建sheet工作表及操作四、读取excel和单元格1.读取 excel 文件2.读取单元格3.获取某一行某一列的数据4.遍历所有单元格5.遍历指定行列范围的单元…

数据结构之堆——算法与数据结构入门笔记(六)

本文是算法与数据结构的学习笔记第六篇&#xff0c;将持续更新&#xff0c;欢迎小伙伴们阅读学习。有不懂的或错误的地方&#xff0c;欢迎交流 引言 当涉及到高效的数据存储和检索时&#xff0c;堆&#xff08;Heap&#xff09;是一种常用的数据结构。上一篇文章中介绍了树和完…

iOS自动化环境搭建(超详细)

1.macOS相关库安装 libimobiledevice > brew install libimobiledevice 使用本机与苹果iOS设备的服务进行通信的库。 ideviceinstaller brew install ideviceinstaller 获取设备udid、安装app、卸载app、获取bundleid carthage > brew install carthage 第三方库…

机器视觉初步5:图像预处理相关技术与原理简介

在机器视觉领域中&#xff0c;图像预处理是一项非常重要的技术。它是指在对图像进行进一步处理之前&#xff0c;对原始图像进行一系列的操作&#xff0c;以提高图像质量、减少噪声、增强图像特征等目的。本文将介绍一些常用的图像预处理技术&#xff0c;并通过配图说明&#xf…

Android CMake

首先了解几个名词 NDK The Android Native Development Kit The Android NDK is a toolset that lets you implement parts of your app in native code, using languages such as C and C. For certain types of apps, this can help you reuse code libraries written in t…

Centos7安装Python3.10

Centos7用yum安装的Python3版本比较旧&#xff0c;想要安装最新版本的Python3需要自己动手编译安装。下面就来讲讲安装步骤&#xff0c;主要分为这么几个步骤&#xff0c;依赖→下载→编译→配置。另外所有操作都是在root用户下进行。 依赖 编译Python源码需要依赖许多库&…

springboot-内置Tomcat

一、springboot的特性之一 基于springboot的特性 自动装配Configuretion 注解 二、springboot内置Tomcat步骤 直接看SpringApplication方法的代码块 总纲&#xff1a; 1、在SpringApplication.run 初始化了一个上下文ConfigurableApplicationContext configurableApplica…

《C++ Primer》--学习4

函数 函数基础 局部静态对象 局部静态对象 在程序的执行路径第一次经过对象定义语句时初始化&#xff0c;并且直到程序终止才被销毁&#xff0c;在此期间即使对象所在函数结束执行也不会对它有影响 指针或引用形参与 const main&#xff1a; 处理命令行选项 列表初始化返回…

机器人参数化建模与仿真,软体机器人

专题一&#xff1a;机器人参数化建模与仿真分析、优化设计专题课程大纲 机器人建模基础 机器人运动学基础几何运动学闭环解解析法建模运动学MATLAB脚本文件编写&#xff08;封闭解、构型绘制&#xff09;、工具箱机器人工作空间&#xff08;离散法、几何法&#xff09;建模工作…

Debian12中Grub2识别Windows

背景介绍&#xff1a;windows10 debian11,2023年6月&#xff0c;Debian 12正式版发布了。抵不住Debian12新特性的诱惑&#xff0c;我将Debian11升级至Debian12。升级成功&#xff0c;但Debian12的Grub2无法识别Window10。于是执行如下命令&#xff1a; debian:~# update-grub G…

MySQL如何在Centos7环境安装:简易指南

目录 前言 一、卸载不要的环境 1.检查本地MySQL是否正在运行 2.停止正在运行的MySQL 二、检查系统安装包 三、卸载这些默认安装包 1.手动一个一个卸载 2.自动卸载全部 四、获取mysql官方yum源 五、安装mysql yum源&#xff0c;对比前后yum源 1.安装前 2.安装中 3.…

认识服务器

1、查看操作系统的信息 CentOS 输入&#xff1a;cat /etc/os-release 字段含义解释NAME操作系统名称CentOS LinuxVERSION操作系统版本7 (Core)ID操作系统标识centosID_LIKE相关操作系统标识rhel fedoraVERSION_ID操作系统版本号7PRETTY_NAME可读性较好的操作系统名称CentOS L…

0004Java程序设计-SSM+JSP医院挂号系统

摘 要 医院挂号&#xff0c;一直以来就是困扰医院提高服务水平的重要环节&#xff0c;特别是医疗水平高、门诊访问量高的综合型医院&#xff0c;门诊拥挤就成了普遍现象。因此&#xff0c;本文提出了医院挂号系统。预约挂号&#xff0c;是借助信息化的技术&#xff0c;面向全社…

PB9如何实现datawindow打印导出PDF,PB导出PDF

PB9如何实现datawindow打印导出PDF&#xff0c;PB导出PDF&#xff1f; 之前的saveas导出pdf&#xff0c;设置非常麻烦。需要 1. 安装gs705w32.exe 2. 设置系统path: C:\gs\gs7.05\bin (以实际安装目录为准) 3. 安装虚拟打印机 PowerBuilder9.0自带的: Sybase\Shared\Power…