<! DOCTYPE html> <meta charset= "UTF-8"/> <meta content= "Width=device-width, initial-scale=1.0, maximum-scale=1.0, user-scalable=0;" name= "viewport"/> <title> Zhi Ling Legends </title> <style type= "Text/css" > Body { width:320px; min-height:568px; Overflow:hidden; margin:0; } #canvas { Background:url (img/lzl.jpg); /* Prize Pictures/* Fixed Center center no-repeat; Background-size:cover; width:320px; min-height:480px; Overflow:hidden; position:relative; } . before { Background:none!important; } #canvas Canvas { Cursor:url ("Img/bird.png") 0 0, auto; /*PC-End gesture Picture * * } </style> <body oncontextmenu= ' return false; ' onselectstart= ' return false; > <div id= "Canvas" > </div> </body> <script type= "Text/javascript" > (function () { Window.onload = function () { /** Prohibit drag settings */ Document.ontouchmove = function (e) { E.preventdefault (); };
/** to determine if the browser supports canvas**/ try { Document.createelement (' canvas '). GetContext (' 2d '); catch (e) { var adddiv = document.createelement (' div '); Alert (' Your phone does not support scraping card effect oh ~! '); } }; var u = navigator.useragent, Mobile = ' PC '; if (u.indexof (' iphone ') >-1) Mobile = ' iphone '; if (U.indexof (' Android ') >-1 | | u.indexof (' Linux ') >-1) Mobile = ' Android '; function Createcanvas (parent, width, height) { var canvas = {}; Canvas.node = document.createelement (' canvas '); Canvas.context = Canvas.node.getContext (' 2d '); Here you can add yourself to the label Canvas.node.width = Width | | 320; Canvas.node.height = Height | | 480; Add ID to Canvas label canvas.node.id = ' Canvastag '; Parent.appendchild (Canvas.node); return canvas; } function init (container, width, height, fillcolor, type) { var canvas = Createcanvas (container, width, height); var ctx = Canvas.context; Define a custom Fillcircle method Ctx.fillcircle = function (x, y, radius, fillcolor) { This.fillstyle = FillColor; This.beginpath (); This.moveto (x, y); This.arc (x, y, radius, 0, Math.PI * 2, false); This.fill (); }; Ctx.clearto = function (FillColor) { Ctx.fillstyle = FillColor; Ctx.fillrect (0, 0, width, height); }; Ctx.clearto (FillColor | | "#ddd"); Canvas.node.addEventListener (mobile = "PC"?) "MouseDown": "Touchstart", function (e) { Canvas.isdrawing = true; }, False); Canvas.node.addEventListener (mobile = "PC"?) "MouseUp": "Touchend", function (e) { Canvas.isdrawing = false; }, False); Canvas.node.addEventListener (mobile = "PC"?) "MouseMove": "Touchmove", function (e) { if (!canvas.isdrawing) { Return } if (type = = ' Android ') { var x = E.changedtouches[0].pagex-this.offsetleft; var y = e.changedtouches[0].pagey-this.offsettop; } else { var x = E.pagex-this.offsetleft; var y = e.pagey-this.offsettop; } var radius = 20; var fillcolor = ' #ff0000 '; ctx.globalcompositeoperation = ' destination-out '; Ctx.fillcircle (x, y, radius, fillcolor); }, False); } var container = document.getElementById (' canvas '); Init (container, 568, ' #696868 ', mobile); })(); </script> |