question.html 7.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197
  1. <!DOCTYPE html>
  2. <html lang="en">
  3. <head>
  4. <meta charset="UTF-8">
  5. <meta name="viewport" content="width=device-width, initial-scale=1.0">
  6. <meta http-equiv="X-UA-Compatible" content="ie=edge">
  7. <title>Document</title>
  8. <link rel="stylesheet" href="../css/question.css">
  9. <script src="../utils/size.js"></script>
  10. </head>
  11. <body>
  12. <div class="content">
  13. <div class="question-container">
  14. <img class="container-bg" src="../image/question/questionbg.jpg" alt="">
  15. <div class="title">
  16. <img src="../image/question/title.png" alt="title">
  17. </div>
  18. <div class="subject">
  19. <img class="inset" src="../image/question/inset.png" alt="inset">
  20. <img class="bottom" src="../image/question/bottom.png" alt="bottom">
  21. <div class="question-box"></div>
  22. <!--
  23. <div class="question" >
  24. <div class="audio">
  25. <audio src="http://www.ytmp3.cn/down/44537.mp3" autoplay="autoplay" preload="auto">
  26. 您的浏览器不支持 audio 标签。
  27. </audio>
  28. <img class="audiobtn" src="../image/question/audiobtn.png" alt="audiobtn">
  29. <span>甜甜圈从左数是第几个?</span>
  30. </div>
  31. <div class="question-photo"></div>
  32. <ul class="option">
  33. <li class="select">第一个</li>
  34. <li>第二个</li>
  35. <li>第三个</li>
  36. </ul>
  37. <div class="order">
  38. <span>1</span><span>/5</span>
  39. </div>
  40. </div>
  41. -->
  42. </div>
  43. </div>
  44. <div class="popup">
  45. <div class="popup-content">
  46. <canvas id="myCanvas" width="255px" height="466px">
  47. 您的浏览器不支持canvas标签。
  48. </canvas>
  49. <img class="bg" src="../image/question/2.jpg" alt="">
  50. <div class="baocun">长按保存,并分享至朋友圈</div>
  51. <div class="code">
  52. <img src="../image/question/2.jpg" alt="">
  53. <div class="text">
  54. <span>长按识别二维码</span>
  55. <span>即可获得小学课文朗读配音奖品</span>
  56. </div>
  57. </div>
  58. <!--
  59. <img class="head" src="../image/question/头像.jpg" alt="">
  60. -->
  61. </div>
  62. </div>
  63. </div>
  64. </body>
  65. <script src="https://code.jquery.com/jquery-3.3.1.min.js"></script>
  66. <script>
  67. var answer = "";
  68. var questionId = "";
  69. var requestId = "";
  70. var data = {
  71. "activityId": "1",
  72. "answer": "",
  73. "questionId": "",
  74. "requestId": ""
  75. }
  76. var ind = 0;
  77. function recursion() {
  78. ajaxData("https://readertest.lingjiao.cn/activity/activity", '7', data, function(result){
  79. var length = result.data.questionNum;
  80. data.questionId = result.data.question.id;
  81. data.requestId = result.data.requestId;
  82. // 一开始创建div 没内容
  83. $("<div></div>", {
  84. "class": "question", // 设置样式类
  85. html: '<div class="order">' +
  86. '<span class="ind">1</span><span>/'+ length +'</span>' +
  87. '</div>', // 设置内容
  88. }).appendTo($('.question-box')); // 追加到body标签
  89. // 初次渲染第一题
  90. renderDiv(ind, result.data.question)
  91. $('.question').eq(ind).children('ul').find('li').on('click', function() {
  92. data.answer = $(this).data('answer');
  93. ind++;
  94. $(this).addClass('select').siblings().removeClass('select');
  95. var that = this;
  96. recursion();
  97. setTimeout(function () {
  98. if( ind >= length) {
  99. $('.popup').show();
  100. return false;
  101. }
  102. $(that).parents('.question').slideUp('slow', function () {
  103. $('.question').eq(ind).find('.ind').text(ind + 1);
  104. });
  105. }, 500)
  106. })
  107. })
  108. }
  109. recursion();
  110. // ajax请求
  111. function ajaxData (url, uid, data, success) {
  112. $.ajax({
  113. url: url,
  114. type: 'POST',
  115. headers: {'uid': uid},
  116. contentType:'application/json;charset=utf-8',
  117. data: JSON.stringify(data),
  118. success: success
  119. });
  120. }
  121. // 渲染元素
  122. function renderDiv (ind, datas) {
  123. var renders = '<div class="audio">' +
  124. '<audio src="'+ datas.audio +'">' +
  125. '您的浏览器不支持 audio 标签。' +
  126. '</audio>' +
  127. '<img class="audiobtn" src="../image/question/audiobtn.png" alt="audiobtn">' +
  128. '<div>'+ datas.content +'</div>' +
  129. '</div>' +
  130. '<div class="question-photo">'+
  131. '<img src="'+ datas.imgUrl +'" alt="">'+
  132. '</div>' +
  133. '<ul class="option">' +
  134. '<li data-answer="A">'+ datas.optionA +'</li>' +
  135. '<li data-answer="B">'+ datas.optionB +'</li>' +
  136. '<li data-answer="C">'+ datas.optionC +'</li>' +
  137. '</ul>'
  138. $('.question').eq(ind).prepend(renders)
  139. }
  140. //canvas绘制图片
  141. //获取Canvas对象(画布)
  142. var canvas = document.getElementById("myCanvas");
  143. //简单地检测当前浏览器是否支持Canvas对象,以免在一些不支持html5的浏览器中提示语法错误
  144. if(canvas.getContext){
  145. //获取对应的CanvasRenderingContext2D对象(画笔)
  146. var ctx = canvas.getContext("2d");
  147. //回调地狱,可优化,暂时这样写
  148. canvasImg('../image/question/2.jpg', 0, 0, '255', '466', function() {
  149. canvasImg('../image/question/2.jpg', 200, 400, '50', '50', function() {
  150. ctx.moveTo(125,20);
  151. ctx.lineTo(125,170);
  152. ctx.fillStyle = '#fff';
  153. ctx.font="14px Arial";
  154. ctx.textAlign="center";
  155. ctx.fillText("王丽丽王丽丽丽丽学前测评报告",125,120);
  156. circleImg('../image/question/2.jpg', 110, 290, 15)
  157. })
  158. })
  159. ctx.restore();
  160. }
  161. function canvasImg (url, x, y, w, h, success) {
  162. //创建新的图片对象
  163. var img = new Image();
  164. //指定图片的URL
  165. img.src = url;
  166. //浏览器加载图片完毕后再绘制图片
  167. img.onload = function(){
  168. //以Canvas画布上的坐标(10,10)为起始点,绘制图像
  169. ctx.drawImage(img, x, y, w, h);
  170. success();
  171. };
  172. }
  173. // 封装了一个简单截取头像的方法
  174. function circleImg(url, x, y, r) {
  175. //创建新的图片对象
  176. var img = new Image();
  177. //指定图片的URL
  178. img.src = url;
  179. ctx.save();
  180. var d =2 * r;
  181. var cx = x + r;
  182. var cy = y + r;
  183. img.onload = function(){
  184. ctx.arc(cx, cy, r, 0, 2 * Math.PI);
  185. ctx.clip();
  186. //以Canvas画布上的坐标(10,10)为起始点,绘制图像
  187. ctx.drawImage(img, x, y, d, d);
  188. };
  189. }
  190. //0.5s后生成图片
  191. setTimeout(function() {
  192. var dataURL = canvas.toDataURL("image/png",1.0);
  193. $('.bg').attr('src', dataURL)
  194. }, 500)
  195. </script>
  196. </html>