목차
1. 서문
2.canvcas 태그
3. 자필 서명 패널
4. 페이지 코드
5. 스크립트 코드 1
6.
웹 프론트엔드 H5 튜토리얼 HTML5 캔버스에서 터치스크린을 지원하는 서명패널의 샘플코드에 대한 자세한 설명

HTML5 캔버스에서 터치스크린을 지원하는 서명패널의 샘플코드에 대한 자세한 설명

Mar 21, 2017 pm 03:31 PM

1. 서문

저는 요즘 너무 바빠서 국경일 이후에 사표를 내고 천천히 일자리를 찾기 시작했습니다. 오늘부터 보름 넘게 일하고 있습니다. 너무 안타깝고.. 면접 과정에서 사기꾼 회사를 연달아 봤습니다. 몇몇 회사는 하루만 근무하고 그 중 밤 10시까지 야근을 하는 회사도 있었습니다. 출근 첫날은 너무 멀고 집에 오는 첫날 버스를 타기에는 너무 피곤해서 버스를 타는 것이 정말 적합하지 않습니다. 면접 때 빅데이터 얘기를 해준다던가.. 회사에 들어와보니 가장 단순한 3레이어를 사용하고 있는 걸 보니 디자인 패턴이 없었다. .. 다행히 지금은 회사가 나쁘지 않아서 일자리를 구하는 것이 과한 것보다 낫다.

2.canvcas 태그

canvas기본 튜토리얼: 태그는 차트 및 기타 이미지와 같은 그래픽을 정의합니다. HTML5의 캔버스 요소는 JavaScript를 사용하여 웹페이지에 이미지를 그립니다. 브러시나 유성 페인트로는 불가능한 애니메이션을 캔버스에서 만들고 조작할 수도 있습니다. 모든 웹 브라우저에 대한 완전한 HTML5 지원은 아직 완료되지 않았지만, 새로운 지원 중에서 캔버스는 이미 거의 모든 최신 브라우저에서 잘 작동합니다. 캔버스에는 경로, 직사각형, 원, 문자를 그리고 이미지를 추가하는 다양한 방법이 있습니다. 저는 회사에 입사한 지 한 달이 되었고 주로 학습에 관한 것입니다. 저는 백엔드 개발을 하고 있으며 이전에는 Oracle 데이터베이스를 사용해 본 적이 없습니다. 이번 달에는 주로 H5 및 css3.0의 몇 가지 새로운 기능에 대해 배웠습니다. 서버에 설치와 배포, 일부 데이터 가져오기 및 내보내기, 데이터 백업 등 프런트엔드 부분도 상대적으로 열악한 편이라 공부도 열심히 해야겠습니다.

3. 자필 서명 패널

회사에서 자동화된 사무실 OA 시스템을 만들고 있습니다. 일부 감사 영역에는 자필 서명 기능을 추가해야 합니다. 처음 시작할 때는 아무런 아이디어도 없었습니다. 이것도 인터넷에서 찾아본 결과 H5에 이런 새로운 캔버스 라벨이 있다는 것을 알게 되었는데 특히나 기뻤습니다. 그래서 그걸 받아서 시도해봤는데 정말 효과가 있었어요.

4. 페이지 코드

@{
    Layout = null;
}<!DOCTYPE html>

<html>
<head>
    <meta name="viewport" content="width=device-width" />
    <title>Testpage</title>
    <script src="~/Assets/jquery-2.1.1.js"></script>
    <script src="~/Assets/bootstrap/bootstrap.js"></script>
    <link href="~/Assets/bootstrap/bootstrap.css" rel="stylesheet" />
    <script src="~/Scripts/WritingPad.js"></script>
    <script src="~/Assets/jq-signature.js"></script>
</head>
<body style="background-color:#b6ff00">

    <button class="btn btn-primary" type="button" style="position:relative">点击我</button>

</body>
</html>
<script>

    $(function () {

        $(".btn,.btn-primary").click(function () {            
        var wp = new WritingPad();            
        //wp.init();        });
    });</script>
로그인 후 복사

5. 스크립트 코드 1

/**
 * 功能:签名canvas面板初始化,为WritingPad.js手写面板js服务。
 * 作者:黄金锋 (549387177@qq.com)
 * 日期:2015-11-15  15:51:01
 * 版本:version 1.0
 */

(function (window, document, $) {
    &#39;use strict&#39;;

  // Get a regular interval for drawing to the screen
  window.requestAnimFrame = (function (callback) {
    return window.requestAnimationFrame || 
      window.webkitRequestAnimationFrame ||
      window.mozRequestAnimationFrame ||
      window.oRequestAnimationFrame ||
      window.msRequestAnimaitonFrame ||
      function (callback) {
        window.setTimeout(callback, 1000/60);
      };
  })();

  /*
  * Plugin Constructor
  */

  var pluginName = &#39;jqSignature&#39;,
      defaults = {
        lineColor: &#39;#222222&#39;,
        lineWidth: 1,
        border: &#39;1px dashed #CCFF99&#39;,
        background: &#39;#FFFFFF&#39;,
        width: 500,
        height: 200,
        autoFit: false
      },
      canvasFixture = &#39;<canvas></canvas>&#39;;

  function Signature(element, options) {
    // DOM elements/objects
    this.element = element;
    this.$element = $(this.element);
    this.canvas = false;
    this.$canvas = false;
    this.ctx = false;
    // Drawing state
    this.drawing = false;
    this.currentPos = {
      x: 0,
      y: 0
    };
    this.lastPos = this.currentPos;
    // Determine plugin settings
    this._data = this.$element.data();
    this.settings = $.extend({}, defaults, options, this._data);
    // Initialize the plugin
    this.init();
  }

  Signature.prototype = {
    // Initialize the signature canvas
    init: function() {
      // Set up the canvas
      this.$canvas = $(canvasFixture).appendTo(this.$element);
      this.$canvas.attr({
        width: this.settings.width,
        height: this.settings.height
      });
      this.$canvas.css({
        boxSizing: &#39;border-box&#39;,
        width: this.settings.width + &#39;px&#39;,
        height: this.settings.height + &#39;px&#39;,
        border: this.settings.border,
        background: this.settings.background,
        cursor: &#39;crosshair&#39;
      });
      // Fit canvas to width of parent
      if (this.settings.autoFit === true) {
        this._resizeCanvas();
      }
      this.canvas = this.$canvas[0];
      this._resetCanvas();
      // Set up mouse events
      this.$canvas.on(&#39;mousedown touchstart&#39;, $.proxy(function(e) {
        this.drawing = true;
        this.lastPos = this.currentPos = this._getPosition(e);
      }, this));
      this.$canvas.on(&#39;mousemove touchmove&#39;, $.proxy(function(e) {
        this.currentPos = this._getPosition(e);
      }, this));
      this.$canvas.on(&#39;mouseup touchend&#39;, $.proxy(function(e) {
        this.drawing = false;
        // Trigger a change event
        var changedEvent = $.Event(&#39;jq.signature.changed&#39;);
        this.$element.trigger(changedEvent);
      }, this));
      // Prevent document scrolling when touching canvas
      $(document).on(&#39;touchstart touchmove touchend&#39;, $.proxy(function(e) {
        if (e.target === this.canvas) {
          e.preventDefault();
        }
      }, this));
      // Start drawing
      var that = this;
      (function drawLoop() {
        window.requestAnimFrame(drawLoop);
        that._renderCanvas();
      })();
    },
    // Clear the canvas
    clearCanvas: function() {
      this.canvas.width = this.canvas.width;
      this._resetCanvas();
    },
    // Get the content of the canvas as a base64 data URL
    getDataURL: function() {
      return this.canvas.toDataURL();
    },

    reLoadData: function () {
        this.$canvas.remove();
        this._data = this.$element.data();

        //for (var i in this.settings) {
        //    alert(i+":"+this.settings[i]);
        //}

        //this.settings = $.extend({}, defaults, this._data);
        this.init();
    },
    // Get the position of the mouse/touch
    _getPosition: function(event) {
      var xPos, yPos, rect;
      rect = this.canvas.getBoundingClientRect();
      event = event.originalEvent;
      // Touch event
      if (event.type.indexOf(&#39;touch&#39;) !== -1) { // event.constructor === TouchEvent
        xPos = event.touches[0].clientX - rect.left;
        yPos = event.touches[0].clientY - rect.top;
      }
      // Mouse event
      else {
        xPos = event.clientX - rect.left;
        yPos = event.clientY - rect.top;
      }
      return {
        x: xPos,
        y: yPos
      };
    },
    // Render the signature to the canvas
    _renderCanvas: function() {
      if (this.drawing) {
        this.ctx.moveTo(this.lastPos.x, this.lastPos.y);
        this.ctx.lineTo(this.currentPos.x, this.currentPos.y);
        this.ctx.stroke();
        this.lastPos = this.currentPos;
      }
    },
    // Reset the canvas context
    _resetCanvas: function() {
      this.ctx = this.canvas.getContext("2d");
      this.ctx.strokeStyle = this.settings.lineColor;
      this.ctx.lineWidth = this.settings.lineWidth;
    },
    // Resize the canvas element
    _resizeCanvas: function() {
      var width = this.$element.outerWidth();
      this.$canvas.attr(&#39;width&#39;, width);
      this.$canvas.css(&#39;width&#39;, width + &#39;px&#39;);
    }
  };

  /*
  * Plugin wrapper and initialization
  */

  $.fn[pluginName] = function ( options ) {
    var args = arguments;
    if (options === undefined || typeof options === &#39;object&#39;) {
      return this.each(function () {
        if (!$.data(this, &#39;plugin_&#39; + pluginName)) {
          $.data(this, &#39;plugin_&#39; + pluginName, new Signature( this, options ));
        }
      });
    } 
    else if (typeof options === &#39;string&#39; && options[0] !== &#39;_&#39; && options !== &#39;init&#39;) {
      var returns;
      this.each(function () {
        var instance = $.data(this, &#39;plugin_&#39; + pluginName);
        if (instance instanceof Signature && typeof instance[options] === &#39;function&#39;) {
            var myArr=Array.prototype.slice.call( args, 1 );
            returns = instance[options].apply(instance, myArr);
        }
        if (options === &#39;destroy&#39;) {
          $.data(this, &#39;plugin_&#39; + pluginName, null);
        }
        //if (options === &#39;reLoadData&#39;) {
        //    //this.$canvas.remove();
        //    $.data(this, &#39;plugin_&#39; + pluginName, null);
        //    this._data = this.$element.data();
        //    this.settings = $.extend({}, defaults, options, this._data);
        //    this.init();
        //}
      });
      return returns !== undefined ? returns : this;
    }
  };

})(window, document, jQuery);
로그인 후 복사

6.

위 내용은 HTML5 캔버스에서 터치스크린을 지원하는 서명패널의 샘플코드에 대한 자세한 설명의 상세 내용입니다. 자세한 내용은 PHP 중국어 웹사이트의 기타 관련 기사를 참조하세요!

본 웹사이트의 성명
본 글의 내용은 네티즌들의 자발적인 기여로 작성되었으며, 저작권은 원저작자에게 있습니다. 본 사이트는 이에 상응하는 법적 책임을 지지 않습니다. 표절이나 침해가 의심되는 콘텐츠를 발견한 경우 admin@php.cn으로 문의하세요.

핫 AI 도구

Undresser.AI Undress

Undresser.AI Undress

사실적인 누드 사진을 만들기 위한 AI 기반 앱

AI Clothes Remover

AI Clothes Remover

사진에서 옷을 제거하는 온라인 AI 도구입니다.

Undress AI Tool

Undress AI Tool

무료로 이미지를 벗다

Clothoff.io

Clothoff.io

AI 옷 제거제

Video Face Swap

Video Face Swap

완전히 무료인 AI 얼굴 교환 도구를 사용하여 모든 비디오의 얼굴을 쉽게 바꾸세요!

뜨거운 도구

메모장++7.3.1

메모장++7.3.1

사용하기 쉬운 무료 코드 편집기

SublimeText3 중국어 버전

SublimeText3 중국어 버전

중국어 버전, 사용하기 매우 쉽습니다.

스튜디오 13.0.1 보내기

스튜디오 13.0.1 보내기

강력한 PHP 통합 개발 환경

드림위버 CS6

드림위버 CS6

시각적 웹 개발 도구

SublimeText3 Mac 버전

SublimeText3 Mac 버전

신 수준의 코드 편집 소프트웨어(SublimeText3)

HTML의 테이블 테두리 HTML의 테이블 테두리 Sep 04, 2024 pm 04:49 PM

HTML의 테이블 테두리 안내. 여기에서는 HTML의 테이블 테두리 예제를 사용하여 테이블 테두리를 정의하는 여러 가지 방법을 논의합니다.

HTML의 중첩 테이블 HTML의 중첩 테이블 Sep 04, 2024 pm 04:49 PM

HTML의 Nested Table에 대한 안내입니다. 여기에서는 각 예와 함께 테이블 내에 테이블을 만드는 방법을 설명합니다.

HTML 여백-왼쪽 HTML 여백-왼쪽 Sep 04, 2024 pm 04:48 PM

HTML 여백-왼쪽 안내. 여기에서는 HTML margin-left에 대한 간략한 개요와 코드 구현과 함께 예제를 논의합니다.

HTML 테이블 레이아웃 HTML 테이블 레이아웃 Sep 04, 2024 pm 04:54 PM

HTML 테이블 레이아웃 안내. 여기에서는 HTML 테이블 레이아웃의 값에 대해 예제 및 출력 n 세부 사항과 함께 논의합니다.

HTML 입력 자리 표시자 HTML 입력 자리 표시자 Sep 04, 2024 pm 04:54 PM

HTML 입력 자리 표시자 안내. 여기서는 코드 및 출력과 함께 HTML 입력 자리 표시자의 예를 논의합니다.

HTML 정렬 목록 HTML 정렬 목록 Sep 04, 2024 pm 04:43 PM

HTML 순서 목록에 대한 안내입니다. 여기서는 HTML Ordered 목록 및 유형에 대한 소개와 각각의 예에 대해서도 설명합니다.

HTML에서 텍스트 이동 HTML에서 텍스트 이동 Sep 04, 2024 pm 04:45 PM

HTML에서 텍스트 이동 안내. 여기서는 Marquee 태그가 구문과 함께 작동하는 방식과 구현할 예제에 대해 소개합니다.

HTML 온클릭 버튼 HTML 온클릭 버튼 Sep 04, 2024 pm 04:49 PM

HTML onclick 버튼에 대한 안내입니다. 여기에서는 각각의 소개, 작업, 예제 및 다양한 이벤트의 onclick 이벤트에 대해 설명합니다.

See all articles