XML/HTML Code復(fù)制內(nèi)容到剪貼板
- <body style="cursor:pointer">
- <canvas id="mycavas" width="1024" height="400" style="border:solid 4px #000000"></canvas>
- <input type="color" id="color1" name="color1"/>
- <output name="a" for="color1" onforminput="innerHTML=color1.value"></output>
- <input type="range" name="points" id="size" min="5" max="20" />
- </body>
JavaScript Code復(fù)制內(nèi)容到剪貼板
- $.Draw = {};
- $.extend($.Draw, {
- D2: "",
- CX:"",
- Box: "mycavas",
- BoxObj:function(){
- this.CX=document.getElementById(this.Box);
- },
- D2:function(){
- this.D2 = this.CX.getContext("2d");
- },
- Cricle: function (x, y, r, color) {
- if (this.D2) {
- this.D2.beginPath();
- this.D2.arc(x, y, r, 0, Math.PI * 2, true);
- this.D2.closePath();
- if (color) {
- this.D2.fillStyle = color;
- }
- this.D2.fill();
- }
- },
- init: function () {
- this.BoxObj();
- this.D2();
- }
-
- })
-
JavaScript Code復(fù)制內(nèi)容到剪貼板
- var color = "#000000";
- var size = 5;
- document.getElementById('color1').onchange = function () {
- color = this.value;
- };
- document.getElementById('size').onchange = function () {
- size = this.value;
- };
- $.Draw.init();
- var tag = false;
- var current = {};
- document.onmousedown = function (option) {
- current.x = option.x;
- current.y = option.y;
- $.Draw.Cricle(option.x, option.y, size, color);
- tag = true;
- }
- document.onmouseup = function () {
- tag = false;
- }
- document.onmousemove = function (option) {
- if (tag) {
- if (size >= 0) {
- $.Draw.Cricle(option.x, option.y, size, color);
- }
- }
- }