在拼接的过程中先执行的代码层级就较低,后拼接的图片层级较高,可以覆盖在之前拼接的图上面,设置单个文字的样式也一样,写在后面
    举例:

    1. function hecheng() {
    2. var c=document.getElementById("myCanvas");
    3. var imgSrc = $("#qrcode img").attr("src");// 二维码src
    4. var bgimgSrc=$("#headimg img").attr("src");
    5. var ctx=c.getContext("2d");
    6. var bgimg = new Image();
    7. bgimg.onload = function(){
    8. ctx.drawImage(bgimg, 47.5, 180, 270, 270);
    9. var img=new Image();
    10. img.setAttribute('crossOrigin','anonymous');
    11. img.onload=function(){
    12. percent = 100;
    13. ctx.drawImage(img,0,0,375,667);
    14. var wuhanjiay=new Image();
    15. // wuhanjiay.setAttribute('crossOrigin','anonymous');
    16. wuhanjiay.onload=function(){
    17. percent = 80;
    18. ctx.drawImage(wuhanjiay,20,73,335,100);
    19. var img_logo=new Image();
    20. img_logo.onload=function(){
    21. percent = 60;
    22. ctx.drawImage(img_logo, 20, 616, 80, 28)
    23. var img_qr=new Image();
    24. img_qr.onload=function(){
    25. percent = 40;
    26. ctx.drawImage(img_qr, 280, 530, 80, 80);
    27. percent = 20;
    28. percent = 10;
    29. var p1 = $('.text .p1').text();
    30. var p2 = $('.text .p2').text();
    31. var p3 = $('.text .p3').text();
    32. var p4 = $('.text .p4').text();
    33. var p5 = $('.text .p5').text();
    34. var p6 = $('.text .p6').text();
    35. var p7 = $('.text .p7').text();
    36. var p8 = $('.text .p8').text();
    37. var str1 = p1;
    38. var str2 = p2;
    39. var str3 = p3;
    40. var str4 = p4;
    41. var str5 = p5;
    42. var str6 = p6;
    43. var str7 = p7;
    44. var str8 = p8;
    45. ctx.font="12px SimSun";
    46. ctx.fillStyle = '#fff';
    47. // ctx.textAlign="left";
    48. ctx.fillText(str4,20,450);
    49. ctx.fillText(str5,20,470);
    50. ctx.fillText(str6,20,490);
    51. ctx.fillText(str7,20,510);
    52. ctx.fillText(str8,20,530);
    53. str9 = "足不出户就让灵魂远游!"
    54. str10 = "扫码接力"
    55. str11 = "领免费听书VIP"
    56. ctx.fillText(str9,124,636,154);
    57. ctx.fillStyle = '#fff';
    58. ctx.font="14px SimSun";
    59. ctx.fillText(str2,20,400);
    60. ctx.fillText(str1,20,380);
    61. ctx.fillText(str3,20,420);
    62. ctx.font="10px SimSun";
    63. ctx.fillText(str10,292,631);
    64. ctx.fillText(str11,281,650);
    65. var t1 = window.setTimeout(function(){
    66. percent = 0;
    67. console.log(percent);
    68. clearTimeout(t1);//去掉定时器
    69. },500);//使用字符串执行方法
    70. }
    71. img_qr.src=imgSrc;
    72. }
    73. img_logo.src="assets/image/jjlelogo2x.png"
    74. };
    75. wuhanjiay.src="assets/image/text2x.png"
    76. }
    77. img.src="assets/image/bg.png";
    78. img.onerror=function(){};
    79. }
    80. bgimg.src=bgimgSrc
    81. }