1.前言

最近实在是太忙了,从国庆之后的辞职,在慢慢的找工作,到今天在现在的这家公司上班大半个月了,太多的心酸泪无以言表,面试过程中,见到的坑货公司是一家又一家,好几家公司自己都只是上一天班就走了,其中有第一天上班就加班到10点的,有一家公司在体育西路那边,太远,第一天回家挤公交也是太累,以前上班都是走路上班的,自己确实不适合挤公交,还有的公司面试的时候和你说什么大数据,性能优化什么的,进公司一看,他们就是用的最简单的三层,没有什么设计模式,总之太多心酸,幸运的是现在这家公司还不错,找工作就是要宁缺毋滥。

2.canvcas标签

canvas基础教程:<canvas> 标签定义图形,比如图表和其他图像。HTML5 的 canvas 元素使用 JavaScript 在网页上绘制图像。甚至可以在 canvas 上创建并操作动画,这不是使用画笔和油彩所能够实现的。跨所有 web 浏览器的完整 HTML5 支持还没有完成,但在新兴的支持中,canvas 已经可以在几乎所有现代浏览器上良好运行。canvas 拥有多种绘制路径、矩形、圆形、字符以及添加图像的方法。来公司一个月了主要也是学习为主,我是做后台开发,以前也没有用过Oracle数据库,这一个月也主要是学习H5的一些新特新,还有就是css3.0,在就是Oracle在服务器上面的安装部署,一些数据导入导出,数据备份啥的,前端的东西都比较差,现在也是一个学习的机会,就当好好学习了。

3.手写签名面板

公司做的是自动化办公OA系统,一些审核的地方需要加入一些手写签名的功能,刚开始做这个也是没有思路,在网上也找了一下资料,后来发现H5有这个canvcas新标签,感到格外是欣喜。于是拿过来试一下,还真可以。

4.页面代码

  1. @{
  2. Layout = null;
  3. }
  4.  
  5. <!DOCTYPE html>
  6.  
  7. <html>
  8. <head>
  9. <meta name="viewport" content="width=device-width" />
  10. <title>Testpage</title>
  11. <script src="~/Assets/jquery-2.1.1.js"></script>
  12. <script src="~/Assets/bootstrap/bootstrap.js"></script>
  13. <link href="~/Assets/bootstrap/bootstrap.css" rel="stylesheet" />
  14. <script src="~/Scripts/WritingPad.js"></script>
  15. <script src="~/Assets/jq-signature.js"></script>
  16. </head>
  17. <body style="background-color:#b6ff00">
  18.  
  19. <button class="btn btn-primary" type="button" style="position:relative">点击我</button>
  20.  
  21. </body>
  22. </html>
  23. <script>
  24.  
  25. $(function () {
  26.  
  27. $(".btn,.btn-primary").click(function () {
  28. var wp = new WritingPad();
  29. //wp.init();
  30. });
  31. });
  32.  
  33. </script>

5.脚本代码一

  1. /**
  2. * 功能:签名canvas面板初始化,为WritingPad.js手写面板js服务。
  3. * 作者:黄金锋 (549387177@qq.com)
  4. * 日期:2015-11-15 15:51:01
  5. * 版本:version 1.0
  6. */
  7.  
  8. (function (window, document, $) {
  9. 'use strict';
  10.  
  11. // Get a regular interval for drawing to the screen
  12. window.requestAnimFrame = (function (callback) {
  13. return window.requestAnimationFrame ||
  14. window.webkitRequestAnimationFrame ||
  15. window.mozRequestAnimationFrame ||
  16. window.oRequestAnimationFrame ||
  17. window.msRequestAnimaitonFrame ||
  18. function (callback) {
  19. window.setTimeout(callback, 1000/60);
  20. };
  21. })();
  22.  
  23. /*
  24. * Plugin Constructor
  25. */
  26.  
  27. var pluginName = 'jqSignature',
  28. defaults = {
  29. lineColor: '#222222',
  30. lineWidth: 1,
  31. border: '1px dashed #CCFF99',
  32. background: '#FFFFFF',
  33. width: 500,
  34. height: 200,
  35. autoFit: false
  36. },
  37. canvasFixture = '<canvas></canvas>';
  38.  
  39. function Signature(element, options) {
  40. // DOM elements/objects
  41. this.element = element;
  42. this.$element = $(this.element);
  43. this.canvas = false;
  44. this.$canvas = false;
  45. this.ctx = false;
  46. // Drawing state
  47. this.drawing = false;
  48. this.currentPos = {
  49. x: 0,
  50. y: 0
  51. };
  52. this.lastPos = this.currentPos;
  53. // Determine plugin settings
  54. this._data = this.$element.data();
  55. this.settings = $.extend({}, defaults, options, this._data);
  56. // Initialize the plugin
  57. this.init();
  58. }
  59.  
  60. Signature.prototype = {
  61. // Initialize the signature canvas
  62. init: function() {
  63. // Set up the canvas
  64. this.$canvas = $(canvasFixture).appendTo(this.$element);
  65. this.$canvas.attr({
  66. width: this.settings.width,
  67. height: this.settings.height
  68. });
  69. this.$canvas.css({
  70. boxSizing: 'border-box',
  71. width: this.settings.width + 'px',
  72. height: this.settings.height + 'px',
  73. border: this.settings.border,
  74. background: this.settings.background,
  75. cursor: 'crosshair'
  76. });
  77. // Fit canvas to width of parent
  78. if (this.settings.autoFit === true) {
  79. this._resizeCanvas();
  80. }
  81. this.canvas = this.$canvas[0];
  82. this._resetCanvas();
  83. // Set up mouse events
  84. this.$canvas.on('mousedown touchstart', $.proxy(function(e) {
  85. this.drawing = true;
  86. this.lastPos = this.currentPos = this._getPosition(e);
  87. }, this));
  88. this.$canvas.on('mousemove touchmove', $.proxy(function(e) {
  89. this.currentPos = this._getPosition(e);
  90. }, this));
  91. this.$canvas.on('mouseup touchend', $.proxy(function(e) {
  92. this.drawing = false;
  93. // Trigger a change event
  94. var changedEvent = $.Event('jq.signature.changed');
  95. this.$element.trigger(changedEvent);
  96. }, this));
  97. // Prevent document scrolling when touching canvas
  98. $(document).on('touchstart touchmove touchend', $.proxy(function(e) {
  99. if (e.target === this.canvas) {
  100. e.preventDefault();
  101. }
  102. }, this));
  103. // Start drawing
  104. var that = this;
  105. (function drawLoop() {
  106. window.requestAnimFrame(drawLoop);
  107. that._renderCanvas();
  108. })();
  109. },
  110. // Clear the canvas
  111. clearCanvas: function() {
  112. this.canvas.width = this.canvas.width;
  113. this._resetCanvas();
  114. },
  115. // Get the content of the canvas as a base64 data URL
  116. getDataURL: function() {
  117. return this.canvas.toDataURL();
  118. },
  119.  
  120. reLoadData: function () {
  121. this.$canvas.remove();
  122. this._data = this.$element.data();
  123.  
  124. //for (var i in this.settings) {
  125. // alert(i+":"+this.settings[i]);
  126. //}
  127.  
  128. //this.settings = $.extend({}, defaults, this._data);
  129. this.init();
  130. },
  131. // Get the position of the mouse/touch
  132. _getPosition: function(event) {
  133. var xPos, yPos, rect;
  134. rect = this.canvas.getBoundingClientRect();
  135. event = event.originalEvent;
  136. // Touch event
  137. if (event.type.indexOf('touch') !== -1) { // event.constructor === TouchEvent
  138. xPos = event.touches[0].clientX - rect.left;
  139. yPos = event.touches[0].clientY - rect.top;
  140. }
  141. // Mouse event
  142. else {
  143. xPos = event.clientX - rect.left;
  144. yPos = event.clientY - rect.top;
  145. }
  146. return {
  147. x: xPos,
  148. y: yPos
  149. };
  150. },
  151. // Render the signature to the canvas
  152. _renderCanvas: function() {
  153. if (this.drawing) {
  154. this.ctx.moveTo(this.lastPos.x, this.lastPos.y);
  155. this.ctx.lineTo(this.currentPos.x, this.currentPos.y);
  156. this.ctx.stroke();
  157. this.lastPos = this.currentPos;
  158. }
  159. },
  160. // Reset the canvas context
  161. _resetCanvas: function() {
  162. this.ctx = this.canvas.getContext("2d");
  163. this.ctx.strokeStyle = this.settings.lineColor;
  164. this.ctx.lineWidth = this.settings.lineWidth;
  165. },
  166. // Resize the canvas element
  167. _resizeCanvas: function() {
  168. var width = this.$element.outerWidth();
  169. this.$canvas.attr('width', width);
  170. this.$canvas.css('width', width + 'px');
  171. }
  172. };
  173.  
  174. /*
  175. * Plugin wrapper and initialization
  176. */
  177.  
  178. $.fn[pluginName] = function ( options ) {
  179. var args = arguments;
  180. if (options === undefined || typeof options === 'object') {
  181. return this.each(function () {
  182. if (!$.data(this, 'plugin_' + pluginName)) {
  183. $.data(this, 'plugin_' + pluginName, new Signature( this, options ));
  184. }
  185. });
  186. }
  187. else if (typeof options === 'string' && options[0] !== '_' && options !== 'init') {
  188. var returns;
  189. this.each(function () {
  190. var instance = $.data(this, 'plugin_' + pluginName);
  191. if (instance instanceof Signature && typeof instance[options] === 'function') {
  192. var myArr=Array.prototype.slice.call( args, 1 );
  193. returns = instance[options].apply(instance, myArr);
  194. }
  195. if (options === 'destroy') {
  196. $.data(this, 'plugin_' + pluginName, null);
  197. }
  198. //if (options === 'reLoadData') {
  199. // //this.$canvas.remove();
  200. // $.data(this, 'plugin_' + pluginName, null);
  201. // this._data = this.$element.data();
  202. // this.settings = $.extend({}, defaults, options, this._data);
  203. // this.init();
  204. //}
  205. });
  206. return returns !== undefined ? returns : this;
  207. }
  208. };
  209.  
  210. })(window, document, jQuery);

6.脚本代码二

  1. /**
  2. * 功能:使用该jQuery插件来制作在线签名或涂鸦板,用户绘制的东西可以用图片的形式保存下来。
  3. * 作者:黄金锋 (549387177@qq.com)
  4. * 日期:2015-11-16 13:51:01
  5. * 版本:version 1.0
  6. */
  7.  
  8. var WritingPad = function () {
  9.  
  10. var current = null;
  11.  
  12. $(function () {
  13.  
  14. initHtml();
  15.  
  16. initTable();
  17.  
  18. initSignature();
  19.  
  20. if ($(".modal")) {
  21. $(".modal").modal("toggle");
  22. } else {
  23. alert("没用手写面板");
  24. }
  25.  
  26. $(document).on("click", "#myClose,.close", null, function () {
  27. $('#mymodal').modal('hide');
  28. $("#mymodal").remove();
  29.  
  30. });
  31.  
  32. $(document).on("click", "#mySave", null, function () {
  33.  
  34. var myImg = $('#myImg').empty();
  35. var dataUrl = $('.js-signature').jqSignature('getDataURL');
  36. var img = $('<img>').attr('src', dataUrl);
  37. $(myImg).append($('<p>').text("图片保存在这里"));
  38. $(myImg).append(img);
  39.  
  40. });
  41.  
  42. $(document).on("click", "#myEmpty", null, function () {
  43. $('.js-signature').jqSignature('clearCanvas');
  44.  
  45. });
  46.  
  47. $(document).on("click", "#myBackColor", null, function () {
  48.  
  49. $('#colorpanel').css('left', '95px').css('top', '45px').css("display", "block").fadeIn();
  50. //$("canvas").css("background", "#EEEEEE");
  51. $("#btnSave").data("sender", "#myBackColor");
  52. });
  53.  
  54. $(document).on("click", "#myColor", null, function () {
  55. $('#colorpanel').css('left', '205px').css('top', '45px').css("display", "block").fadeIn();
  56. $("#btnSave").data("sender", "#myColor");
  57. });
  58.  
  59. $(document).on("mouseover", "#myTable", null, function () {
  60.  
  61. if ((event.srcElement.tagName == "TD") && (current != event.srcElement)) {
  62. if (current != null) { current.style.backgroundColor = current._background }
  63. event.srcElement._background = event.srcElement.style.backgroundColor;
  64. //$("input[name=DisColor]").css("background-color", event.srcElement.style.backgroundColor);
  65. //var color = event.srcElement.style.backgroundColor;
  66. //var strArr = color.substring(4, color.length - 1).split(',');
  67. //var num = showRGB(strArr);
  68. //$("input[name=HexColor]").val(num);
  69. current = event.srcElement;
  70. }
  71.  
  72. });
  73.  
  74. $(document).on("mouseout", "#myTable", null, function () {
  75.  
  76. if (current != null) current.style.backgroundColor = current._background
  77.  
  78. });
  79.  
  80. $(document).on("click", "#myTable", null, function () {
  81.  
  82. if (event.srcElement.tagName == "TD") {
  83. var color = event.srcElement._background;
  84. if (color) {
  85. $("input[name=DisColor]").css("background-color", color);
  86. var strArr = color.substring(4, color.length - 1).split(',');
  87. var num = showRGB(strArr);
  88. $("input[name=HexColor]").val(num);
  89. }
  90. }
  91.  
  92. });
  93.  
  94. $(document).on("click", "#btnSave", null, function () {
  95.  
  96. $('#colorpanel').css("display", "none");
  97. var typeData = $("#btnSave").data("sender");
  98. var HexColor = $("input[name=HexColor]").val();
  99. var data = $(".js-signature").data();
  100. if (typeData == "#myColor") {
  101. data["plugin_jqSignature"]["settings"]["lineColor"] = HexColor;
  102. $('.js-signature').jqSignature('reLoadData');
  103. }
  104. if (typeData == "#myBackColor") {
  105.  
  106. data["plugin_jqSignature"]["settings"]["background"] = HexColor;
  107. $('.js-signature').jqSignature('reLoadData');
  108. }
  109. });
  110.  
  111. $("#mymodal").on('hide.bs.modal', function () {
  112. $("#colorpanel").remove();
  113. $("#mymodal").remove();
  114. $("#myTable").remove();
  115. });
  116.  
  117. });
  118.  
  119. function initHtml() {
  120.  
  121. var html = '<div class="modal" id="mymodal">' +
  122. '<div class="modal-dialog">' +
  123. '<div class="modal-content">' +
  124. '<div class="modal-header">' +
  125. '<button type="button" class="close" data-dismiss="modal"><span aria-hidden="true">&times;</span><span class="sr-only">Close</span></button>' +
  126. '<h4 class="modal-title">手写面板</h4>' +
  127. '</div>' +
  128. '<div class="modal-body">' +
  129. '<div class="js-signature" id="mySignature">' +
  130. '</div>' +
  131. '<div>' +
  132. '<button type="button" class="btn btn-default" id="myEmpty">清空面板</button>' +
  133. '<button type="button" class="btn btn-default" id="myBackColor">设置背景颜色</button>' +
  134. //'<div style="position:absolute;relative">' +
  135. '<button type="button" class="btn btn-default" id="myColor">设置字体颜色</button>' +
  136. '<div id="colorpanel" style="position:absolute;z-index:99;display:none"></div>' +
  137. //'</div>'+
  138. '</div>' +
  139. '</div>' +
  140. '<div class="modal-footer">' +
  141.  
  142. '<button type="button" class="btn btn-default" id="myClose">关闭</button>' +
  143. '<button type="button" class="btn btn-primary" id="mySave">保存</button>' +
  144. '<div id="myImg">' +
  145. '<div>' +
  146.  
  147. '</div>' +
  148. '</div>' +
  149. '</div>' +
  150. '</div>';
  151.  
  152. $('body').append(html);
  153. }
  154.  
  155. function initTable() {
  156. var colorTable = "";
  157. var ColorHex = new Array('00', '33', '66', '99', 'CC', 'FF');
  158. var SpColorHex = new Array('FF0000', '00FF00', '0000FF', 'FFFF00', '00FFFF', 'FF00FF');
  159. for (var i = 0; i < 2; i++)
  160. {
  161. for (var j = 0; j < 6; j++)
  162. {
  163. colorTable = colorTable + '<tr height=12>';
  164. colorTable = colorTable + '<td width=11 style="background-color:#000000"></td>';
  165.  
  166. if (i == 0)
  167. {
  168. colorTable = colorTable + '<td width=11 style="background-color:#' + ColorHex[j] + ColorHex[j] + ColorHex[j] + '"></td>';
  169. }
  170. else
  171. {
  172. colorTable = colorTable + '<td width=11 style="background-color:#' + SpColorHex[j] + '"></td>';
  173. }
  174.  
  175. //colorTable = colorTable + '<td width=11 style="background-color:#000000"></td>';
  176.  
  177. for (var k = 0; k < 3; k++)
  178. {
  179. for (l = 0; l < 6; l++)
  180. {
  181. colorTable = colorTable + '<td width=11 style="background-color:#' + ColorHex[k + i * 3] + ColorHex[l] + ColorHex[j] + '"></td>';
  182. }
  183. }
  184. colorTable = colorTable + '</tr>';
  185.  
  186. }
  187. }
  188. colorTable =
  189. '<table border="1" id="myTable" cellspacing="0" cellpadding="0" style="border-collapse: collapse;cursor:pointer;" bordercolor="000000">'
  190. + colorTable + '</table>' +
  191. '<table width=225 border="0" cellspacing="0" cellpadding="0" style="border:1px #000000 solid;border-collapse: collapse;background-color:#000000">' +
  192. '<tr style="height:30px">' +
  193. '<td colspan=21 bgcolor=#cccccc>' +
  194.  
  195. '<table cellpadding="0" cellspacing="1" border="0" style="border-collapse: collapse">' +
  196. '<tr>' +
  197. '<td width="3"><input type="text" name="DisColor" size="6" disabled style="border:solid 1px #000000;background-color:#ffff00"></td>' +
  198. '<td width="3"><input type="text" name="HexColor" size="7" style="border:inset 1px;font-family:Arial;" value="#000000"></td>' +
  199. '<td width="3"><button type="button" class="btn btn-primary btn-sm" id="btnSave">确认</button></td>' +
  200. '</tr>' +
  201. '</table>' +
  202.  
  203. '</td>' +
  204. '</tr>' +
  205. '</table>';
  206. $("#colorpanel").append(colorTable);
  207. }
  208.  
  209. function initSignature() {
  210.  
  211. if (window.requestAnimFrame) {
  212. var signature = $("#mySignature");
  213. signature.jqSignature({ width: 500, height: 200, border: '1px solid red', background: '#16A085', lineColor: '#ABCDEF', lineWidth: 2, autoFit: false });
  214. //{ width: 600, height: 200, border: '1px solid red', background: '#16A085', lineColor: '#ABCDEF', lineWidth: 2, autoFit: true }
  215. } else {
  216.  
  217. alert("请加载jq-signature.js");
  218. return;
  219. }
  220. }
  221.  
  222. function showRGB(arr) {
  223. hexcode = "#";
  224. for (x = 0; x < 3; x++) {
  225. var n = arr[x];
  226. if (n == "") n = "0";
  227. if (parseInt(n) != n)
  228. return alert("RGB颜色值不是数字!");
  229. if (n > 255)
  230. return alert("RGB颜色数字必须在0-255之间!");
  231. var c = "0123456789ABCDEF", b = "", a = n % 16;
  232. b = c.substr(a, 1); a = (n - a) / 16;
  233. hexcode += c.substr(a, 1) + b
  234. }
  235. return hexcode;
  236. }
  237.  
  238. function init() {
  239.  
  240. }
  241.  
  242. return {
  243. init: function () {
  244. init();
  245. }
  246. };
  247. }

HTML5 中canvas支持触摸屏的签名面板的更多相关文章

  1. jSignature做手动签名,canvas支持触摸屏的签名涂鸦插件

    整理的前面可以用的: <!doctype html> <html lang="en"> <head> <meta charset=&quo ...

  2. html5中不再支持的元素

    html5中不再支持的元素:1.acronym(建议abbr) : 定义首字母缩写2.applet(建议object): 定义 applet3.basefont(使用css控制)4.big(使用css ...

  3. H5_0009:关于HTML5中Canvas的宽、高设置问题

    关于HTML5中Canvas的宽.高设置问题 Canvas元素默认宽 300px, 高 150px, 设置其宽高可以使用如下方法(不会被拉伸): 方法一:        <canvas widt ...

  4. html5中canvas的使用 获取鼠标点击页面上某点的RGB

    1.html5中的canvas在IE9中可以跑起来.在IE8则跑不起来,这时候就需要一些东西了. 我推荐这种方法,这样显得代码不乱. <!--[if lt IE9]> <script ...

  5. HTML5中Canvas概述

    一.HTML5 Canvas历史 Canvas的概念最初是由苹果公司提出的,用于在Mac OS X WebKit中创建控制板部件(dashboard widget).在Canvas出现之前,开发人员若 ...

  6. HTML5中canvas介绍

    1.什么是Canvas canvas 是 HTML5 提供的一个用于展示绘图效果的标签 canvas 提供了一个空白的图形区域,可以使用特定的JavaScript API来绘画图形(canvas 2D ...

  7. html5中Canvas为什么要用getContext('2d')

    HTML DOM getContext() 方法 HTML DOM Canvas 对象 定义和用法 getContext() 方法返回一个用于在画布上绘图的环境. 语法 Canvas.getConte ...

  8. 在html5中不支持<table>的cellpadding 和 cellspacing ; 2) 如何用css实现 cellpadding, cellspacing ; 3) tr , th 是 有 border, 没有 padding 的.

    1.初始: <!DOCTYPE html> <html lang="en"> <head> <meta charset="UTF ...

  9. html5中audio支持音频格式

    HTML5 Audio标签能够支持wav, mp3, ogg, acc, webm等格式,但有个很重要的音乐文件格式midi(扩展名mid)却在各大浏览器中都没有内置的支持.不是所有的浏览器都支持MP ...

随机推荐

  1. 在CTabCtrl上动态创建CListCtrl控件

    m_List.Create(WS_OVERLAPPED|WS_CHILD|WS_VISIBLE|LVS_REPORT|LVS_AUTOARRANGE|LVS_SHOWSELALWAYS|LVS_EDI ...

  2. html的<head><title><meta>

    head <head>用来标记HTML的头部,里面通常需要包括标题,基础信息,源信息等,定义在HTML头部的内容往往不会在网页上直接显示 title <title>的内容设置在 ...

  3. 微信微博分享注意事项(sharesdk)

    0.(重要)如果接入多渠道可以考虑微博微信appid appkey等信息放到服务端,方便临时修改又可避免很多渠道时替换ShareSDK.xml文件出错. 但是cocos2dx-2.x版本使用代码配置a ...

  4. DW与DM

    DW组成部分简介 DW的组成部分有:针对数据源的分析.数据的ETL.数据的存储结构,元数据管理等. 数据源分析 主要是分析要抽取哪些数据,如何抽取(全量还是增量)?它的更新周期是怎么样的?它的数据质量 ...

  5. Hadoop step by step _ install and configuration environment

    1.安装centos linux系统. 2.配置静态IP 3.配置防火墙 4.添加hadoop用户 5.检查并安装jdk 配置环境变量 6.配置sshd服务 7.配置ssh免密码登录 8.格式化nam ...

  6. 关于volatile和synchronized

    这个可能是最好的对比volatile和synchronized作用的文章了.volatile是一个变量修饰符,而synchronized是一个方法或块的修饰符.所以我们使用这两种关键字来指定三种简单的 ...

  7. java如果读取xml内容

    本文介绍的是使用dom4j方式读取,如需要其他方式可自行百度. 1.首先导入dom4j的jar包:http://www.dom4j.org/dom4j-1.6.1/ 2.准备xml文件 <?xm ...

  8. python中怎么查看当前工作目录和更改工作目录

    查询当前目录:os.getcwd() 更改当前目录:os.chdir()

  9. Unity-WIKI 之 SplashScreen

    组件功能 在屏幕上的一个启动画面消失,等待几秒钟(或等待用户输入),然后淡出,下一个场景加载. 组件源码 using UnityEngine; using System.Collections; // ...

  10. 【转载】Jmeter获取响应结果中参数出现的次数

    在测试中,有时候会遇到要统计响应结果中某个参数出现了多少次,如果量级很大,一个一个数不太现实,下面讲一下实现自动打印出该参数出现的次数的方法. 例如我的响应信息为:{"ip":&q ...