Canvas translate- 平移
<!DOCTYPE html> <html lang="en"> <head> <meta charset="UTF-8"> <title>translate</title> </head> <body> <canvas id='myCanvas' width='800' height='600'> your browser does not support canvas </canvas> <script type="text/javascript"> var c = document.getElementById('myCanvas'); var ctx = c.getContext('2d'); ctx.beginPath(); ctx.strokeStyle = '#000000'; ctx.strokeRect(10, 10, 150, 100); ctx.translate(50, 100); ctx.beginPath(); ctx.strokeStyle = '#cccccc'; ctx.strokeRect(10, 10, 150, 100); </script> </body> </html>