forked from adam806/H5_questionnaire
-
Notifications
You must be signed in to change notification settings - Fork 0
/
H5_questionnaire.html
818 lines (724 loc) · 23.9 KB
/
H5_questionnaire.html
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1, maximum-scale=1, user-scalable=no">
<link href="//cdn.bootcss.com/animate.css/3.5.2/animate.css" rel="stylesheet">
<script src="js/zepto.min.js"></script>
<script src="js/touch.js"></script>
<script src="http://res.wx.qq.com/open/js/jweixin-1.0.0.js"></script> <!--微信jssdk-->
<title>H5调查问券模板</title>
<style>
* {
padding: 0;
margin: 0;
}
.loadingPage {
background: #0000ff;
width: 100%;
}
section {
width: 100%;
position: absolute;
}
.mainContainer {
display: none;
}
.questionNum {
position: fixed;
z-index: 2;
width: 100%;
text-align: center;
}
.page_Footer {
position: fixed;
z-index: 2;
width: 100%;
text-align: center;
bottom: 15px;
}
.playMusicBtn {
position: fixed;
z-index: 2;
right: 43px;
top: 20px;
}
.playMusicNeedle {
position: fixed;
z-index: 2;
right: 42px;
/*-webkit-transform: rotate(30deg);*/
/*transform: rotate(20deg);*/
}
.needleRotate {
-webkit-animation: neeleRotateframes .3s linear both;
animation: neeleRotateframes .3s linear both;
}
.needleRotateBack {
-webkit-animation: needleRotateBackframes .3s linear both;
animation: needleRotateBackframes .3s linear both;
}
@-webkit-keyframes needleRotateBackframes {
100% {
-webkit-transform: rotate(20deg);
}
}
@keyframes needleRotateBackframes {
100% {
transform: rotate(20deg);
}
}
@-webkit-keyframes neeleRotateframes {
100% {
-webkit-transform: rotate(-20deg);
}
}
@keyframes neeleRotateframes {
100% {
transform: rotate(-20deg);
}
}
.musicRotate {
-webkit-animation: musicRotateKeyframes 1s linear infinite both;
animation: musicRotateKeyframes 1s linear infinite both;
}
@-webkit-keyframes musicRotateKeyframes {
0% {
-webkit-transform: rotate(0deg);
}
100% {
-webkit-transform: rotate(360deg);
}
}
@keyframes musicRotateKeyframes {
0% {
transform: rotate(0deg);
}
100% {
transform: rotate(360deg);
}
}
.nextBtn {
width: 50%;
position: absolute;
top: 71%;
left: 27%;
display: none;
}
.page1 {
background: url(http://yunyunlive.oss-cn-beijing.aliyuncs.com/survey/homeBG.png) no-repeat;
-webkit-background-size: cover;
background-size: cover;
}
.page2 {
background: url(http://yunyunlive.oss-cn-beijing.aliyuncs.com/survey/questionBg.png) no-repeat;
-webkit-background-size: cover;
background-size: cover;
}
.page3 {
background: url(http://yunyunlive.oss-cn-beijing.aliyuncs.com/survey/homeBG.png) no-repeat;
-webkit-background-size: cover;
background-size: cover;
}
.page4 {
background: url(http://yunyunlive.oss-cn-beijing.aliyuncs.com/survey/questionBg.png) no-repeat;
-webkit-background-size: cover;
background-size: cover;
}
.page5 {
background: url(http://yunyunlive.oss-cn-beijing.aliyuncs.com/survey/homeBG.png) no-repeat;
-webkit-background-size: cover;
background-size: cover;
}
.page6 {
background: url(http://yunyunlive.oss-cn-beijing.aliyuncs.com/survey/questionBg.png) no-repeat;
-webkit-background-size: cover;
background-size: cover;
}
.hide {
display: none;
}
.resultPage {
background: url(http://yunyunlive.oss-cn-beijing.aliyuncs.com/survey/resultBG.png) no-repeat;
-webkit-background-size: cover;
background-size: cover;
}
.page_outFromTop {
-webkit-animation: page_outFromTopFram .5s linear both;
animation: page_outFromTopFram .5s linear both;
}
@-webkit-keyframes page_outFromTopFram {
100% {
-webkit-transform: translateY(-100%);
}
}
@keyframes page_outFromTopFram {
100% {
transform: translateY(-100%);
}
}
.page_inFromBottom {
-webkit-animation: page_inFromBottomFram .5s linear both;
animation: page_inFromBottomFram .5s linear both;
}
@-webkit-keyframes page_inFromBottomFram {
0% {
-webkit-transform: translateY(100%);
}
100% {
-webkit-transform: translateY(0%);
}
}
@keyframes page_inFromBottomFram {
0% {
transform: translateY(100%);
}
100% {
transform: translateY(0%);
}
}
.page_outFromBottom {
-webkit-animation: page_outFromBottomFram .5s linear both;
animation: page_outFromBottomFram .5s linear both;
}
@-webkit-keyframes page_outFromBottomFram {
100% {
-webkit-transform: translateY(100%);
}
}
@keyframes page_outFromBottomFram {
100% {
-webkit-transform: translateY(100%);
}
}
.page_inFromTop {
-webkit-animation: page_inFormTopFram .5s linear both;
animation: page_inFormTopFram .5s linear both;
}
@-webkit-keyframes page_inFormTopFram {
0% {
-webkit-transform: translateY(-100%);
}
100% {
-webkit-transform: translateY(0%);
}
}
@keyframes page_inFormTopFram {
0% {
transform: translateY(-100%);
}
100% {
transform: translateY(0%);
}
}
.page_outFromLeft {
-webkit-animation: page_outFromLeftFram .5s linear both;
animation: page_outFromLeftFram .5s linear both;
}
@-webkit-keyframes page_outFromLeftFram {
100% {
-webkit-transform: translateX(-100%);
}
}
@keyframes page_outFromLeftFram {
100% {
transform: translateX(-100%);
}
}
.page_inFromRight {
-webkit-animation: page_inFromRightFram .5s linear both;
animation: page_inFromRightFram .5s linear both;
}
@-webkit-keyframes page_inFromRightFram {
0% {
-webkit-transform: translateX(100%);
}
100% {
-webkit-transform: translateX(0%);
}
}
@keyframes page_inFromRightFram {
0% {
transform: translateX(100%);
}
100% {
transform: translateX(0%);
}
}
.page_outFromRight {
-webkit-animation: page_outFromRightFram .5s linear both;
animation: page_outFromRightFram .5s linear both;
}
@-webkit-keyframes page_outFromRightFram {
100% {
-webkit-transform: translateX(100%);
}
}
@keyframes page_outFromRightFram {
100% {
transform: translateX(100%);
}
}
.page_inFromLeft {
-webkit-animation: page_inFromLeftFram .5s linear both;
animation: page_inFromLeftFram .5s linear both;
}
@-webkit-keyframes page_inFromLeftFram {
0% {
-webkit-transform: translateX(-100%);
}
100% {
-webkit-transform: translateX(0%);
}
}
@keyframes page_inFromLeftFram {
0% {
transform: translateX(-100%);
}
100% {
transform: translateX(0%);
}
}
.question_Title {
color: #000;
}
.question_And_Options {
position: absolute;
width: 80%;
height: auto;
top: 25%;
border: 1px solid #000;
left: 8%;
}
.question_And_Options li {
list-style: none;
display: none;
}
.choseBGC {
background: #a9c700;
}
.choseB {
margin-top: 20px;
}
.tip_Pop {
position: absolute;
top: 50%;
left: 8%;
width: 80%;
display: none;
}
.resultPage {
text-align: center;
}
.result_Title {
position: relative;
margin-top: 5%;
}
.result_Point {
width: 100%;
text-align: center;
}
.result_Word {
display: inline-block;
width: 35%;
}
.result_Num {
background: url(http://yunyunlive.oss-cn-beijing.aliyuncs.com/survey/numBG.png) no-repeat;
background-size: contain;
background-position: 0;
font-size: 40px;
font-weight: bold;
display: inline-block;
padding: 0 4%;
}
.result_Editor_Photo {
width: 50%;
}
.result_Description {
font-weight: bold;
}
.shareBtn {
width: 30%;
}
.remind {
font-weight: bold;
}
.check_Result {
font-weight: bold;
}
.QR_Code {
width: 40%;
}
</style>
</head>
<body>
<div class="loadingPage" id="loadingPage">
加载中,请稍等!
</div>
<div class="mainContainer">
<audio class="playMusic" id="playMusic" loop="loop" autoplay="autoplay"
src="http://yunyunlive.oss-cn-beijing.aliyuncs.com/survey/bgm.mp3"></audio>
<div class="questionNum">
<span class="question_Num">1</span>/<span>100</span>
</div>
<div class="page_Footer">这是页脚</div>
<img class="playMusicBtn musicRotate" id="playMusicBtn" src="images/playMusic.png">
<img class="playMusicNeedle needleRotateBack" src="images/needle.png">
<section class="page1">
<div class="question_And_Options">
<p class="question_Title">正在获取问题...</p>
<br>
<ul class="options_List">
<li class="option choseA">A:是</li>
<li class="option choseB">B:否</li>
</ul>
</div>
<p class="tip_Pop">正在获取吐槽...</p>
<img class="nextBtn" src="http://yunyunlive.oss-cn-beijing.aliyuncs.com/survey/next.png">
</section>
<section class="page2 hide resultPage">
<img class="result_Title" src="http://yunyunlive.oss-cn-beijing.aliyuncs.com/survey/resn1.png">
<div class="result_Point">
<img class="result_Word" src="http://yunyunlive.oss-cn-beijing.aliyuncs.com/survey/resultTitle.png">
<span class="result_Num">0</span>
</div>
<p class="result_Description">这是一段根据得分得出的描述</p>
<div class="result_Editor">
<img class="result_Editor_Photo"
src="http://yunyunlive.oss-cn-beijing.aliyuncs.com/survey/testResult_contentAndButton.png">
</div>
<img class="shareBtn" src="http://yunyunlive.oss-cn-beijing.aliyuncs.com/survey/shareBtn.png">
<p class="remind">长按二维码关注"自在"公众号</p>
<p class="check_Result">查看抽奖结果</p>
<img class="QR_Code" src="http://yunyunlive.oss-cn-beijing.aliyuncs.com/survey/recognize.jpg">
</section>
<section class="page3 hide">
<br>
<br>
<br>
第三页<br>
第三页<br>
第三页<br>
第三页<br>
第三页<br>
<img class="nextBtn" src="http://yunyunlive.oss-cn-beijing.aliyuncs.com/survey/next.png">
</section>
<section class="page4 hide">
<br>
<br>
<br>
第四页<br>
第四页<br>
第四页<br>
第四页<br>
第四页<br>
<img class="nextBtn" src="http://yunyunlive.oss-cn-beijing.aliyuncs.com/survey/next.png">
</section>
<section class="page5 hide">
<br>
<br>
<br>
第五页<br>
第五页<br>
第五页<br>
第五页<br>
第五页<br>
<img class="nextBtn" src="http://yunyunlive.oss-cn-beijing.aliyuncs.com/survey/next.png">
</section>
<section class="page6 hide">
<br>
<br>
<br>
第六页<br>
第六页<br>
第六页<br>
第六页<br>
第六页<br>
<img class="nextBtn" src="http://yunyunlive.oss-cn-beijing.aliyuncs.com/survey/next.png">
</section>
</div>
<script>
var winWidth;
var winHeight;
var prePage;
var nowPage = 1;
var maxPage = 6;
var outPage;
var inPage;
var isAnimation = false;
var selectedAnswer = "y";
var curQid;
var curQuestion;
var tipY;
var tipN;
var nextYId;
var nextNId;
var isChosen = false;
//获取相关设备尺寸
function getWindowSize() {
//获取窗口宽度,下方用于兼容浏览器
if (window.innerWidth) {
winWidth = window.innerWidth;
} else if ((document.body) && (document.body.clientWidth)) {
winWidth = document.body.clientWidth;
}
//获取窗口高度,下方用于兼容浏览器
if (window.innerHeight) {
winHeight = window.innerHeight;
} else if ((document.body) && (document.body.clientHeight)) {
winHeight = document.body.clientHeight;
}
var page1 = document.getElementsByTagName("section");
for (var i = 0; i < page1.length; i++) {
page1[i].style.height = winHeight + "px";
}
var load = document.getElementById("loadingPage");
load.style.height = winHeight + "px";
}
window.onload = function () {
getWindowSize();
loading();
swipe();
getQuestion(0);
};
function loading() {
if (document.readyState == "complete") {
$(".loadingPage").hide();
$(".mainContainer").show();
}
}
//手指划屏事件
function swipe() {
document.addEventListener("touchmove", function (event) {
event.preventDefault();
}, false);
$(document).swipeUp(function () { //手指上划
if (isAnimation == false) {
goPage("down");
}
});
$(document).swipeDown(function () { //手指下划
if (isAnimation == false) {
goPage("pre");
}
});
$(document).swipeLeft(function () { //手指左划
if (isAnimation == false) {
goPage("left");
}
});
$(document).swipeRight(function () { //手指右划
if (isAnimation == false) {
goPage("right");
}
})
}
//翻页事件
function goPage(stage) {
if (stage == "down") {
prePage = nowPage;
if (nowPage == maxPage) {
nowPage = 1;
} else {
nowPage++;
}
animationBasic("down");
} else if (stage == "pre") {
prePage = nowPage;
if (nowPage == 1) {
nowPage = maxPage;
} else {
nowPage--;
}
animationBasic("pre");
} else if (stage == "left") {
prePage = nowPage;
if (nowPage == maxPage) {
nowPage = 1;
} else {
nowPage++;
}
animationBasic("left");
} else if (stage == "right") {
prePage = nowPage;
if (nowPage == 1) {
nowPage = maxPage;
} else {
nowPage--;
}
animationBasic("right");
}
}
//基本划屏动画效果
function animationBasic(direction) {
if (direction == "down") {
outPage = "page_outFromTop";
inPage = "page_inFromBottom";
} else if (direction == "pre") {
outPage = "page_outFromBottom";
inPage = "page_inFromTop";
} else if (direction == "left") {
outPage = "page_outFromLeft";
inPage = "page_inFromRight";
} else if (direction == "right") {
outPage = "page_outFromRight";
inPage = "page_inFromLeft";
}
$(".page" + prePage).removeClass("hide").addClass(outPage);
$(".page" + nowPage).removeClass("hide").addClass(inPage);
isAnimation = true;
setTimeout(function () {
$(".page" + prePage).removeClass(outPage).addClass("hide");
$(".page" + nowPage).removeClass(inPage);
isAnimation = false;
}, 500)
}
//音乐暂停和播放
function playMusic() {
var playMusic = document.getElementById("playMusic");
if (playMusic.paused) {
playMusic.play();
} else {
playMusic.pause();
}
}
$(".playMusicBtn").click(function () {
playMusic();
if ($(".playMusicBtn").hasClass("musicRotate") || $(".playMusicNeedle").hasClass("needleRotate") == false) {
$(".playMusicBtn").removeClass("musicRotate");
$(".playMusicNeedle").addClass("needleRotate");
$(".playMusicNeedle").removeClass("needleRotateBack");
} else {
$(".playMusicBtn").addClass("musicRotate");
$(".playMusicNeedle").removeClass("needleRotate");
$(".playMusicNeedle").addClass("needleRotateBack");
}
});
//绑定数据
function getQuery(name) {
url = window.location.href;
name = name.replace(/[\[\]]/g, "\\$&");
var regex = new RegExp("[?&]" + name + "(=([^&#]*)|&|#|$)"),
results = regex.exec(url);
if (!results) return null;
if (!results[2]) return '';
return decodeURIComponent(results[2].replace(/\+/g, " "));
}
$(".option").click(function () {
if(isChosen==false){
$(this).addClass("choseBGC");
}
});
//取得问题
function getQuestion(qid) {
var sid = getQuery("sid");
console.log("向服务器发送的qid是" + qid);
$.post("answer.php?sid=" + sid + "&qid=" + qid + "&a=" + selectedAnswer, function (question) {
curQid = question.id;
if (curQid < 0) {
console.log(question);
isLastQuestion(question);
} else {
console.log("从服务器取回的这道题的curQid是" + curQid);
curQuestion = question;
showQuestion();
tipY = question.answers.y.pop;
tipN = question.answers.n.pop;
$(".question_And_Options li").show();
console.log("下方console出的是从服务器取回的当前这道题目");
console.log(question);
}
}, 'json');
}
//显示问题
function showQuestion() {
$(".question_Title").text(curQuestion.text);
}
//点击是
$(".choseA").bind("click", function () {
if (isChosen == false) {
selectedAnswer = "y";
$(".tip_Pop").text(tipY).show();
$(".nextBtn").show();
isChosen = true;
return isChosen;
console.log(isChosen);
}
// $(".choseB").unbind("click");//选中一个选项后其他项则不可点击
});
//点击否
$(".choseB").bind("click", function () {
if (isChosen == false) {
selectedAnswer = "n";
$(".tip_Pop").text(tipN).show();
$(".nextBtn").show();
isChosen = true;
return isChosen;
}
// $(".choseA").unbind("click");//选中一个选项后其他项则不可点击
});
//点击继续按钮
$(".nextBtn").click(function () {
getQuestion(curQid);
console.log("点击继续按钮后已经取得了问题");
$(".nextBtn").hide();
$(".tip_Pop").hide();
$(".option").removeClass("choseBGC");
isChosen = false;
});
//最后一道题
function isLastQuestion(result) {
console.log("下方显示result");
console.log(result);
$(".page1").hide();
$(".page2").show();
$(".questionNum").hide();
$(".result_Title").attr("src", "http://yunyunlive.oss-cn-beijing.aliyuncs.com/survey/resn" + result.type + ".png");
$(".result_Num").text(result.point);
$(".result_Description").text(result.detail);
}
//微信分享config
wx.config({
debug: false, // 开启调试模式,调用的所有api的返回值会在客户端alert出来,若要查看传入的参数,可以在pc端打开,参数信息会通过log打出,仅在pc端时才会打印。
appId: 'wx1b995d5a13c1d4c4', // 必填,公众号的唯一标识
timestamp: '<?=$timestamp?>', // 必填,生成签名的时间戳
nonceStr: '<?=$nonceStr?>', // 必填,生成签名的随机串
signature: '<?=$signature?>',// 必填,签名,见附录1
jsApiList: ['onMenuShareTimeline', 'onMenuShareAppMessage'] // 必填,需要使用的JS接口列表,所有JS接口列表见附录2
});
wx.ready(function () {
//微信分享给朋友
wx.onMenuShareAppMessage({
title: '七夕有奖趣味测试', // 分享标题
desc: '测测你的撩汗指数,让你七夕不孤单!', // 分享描述
link: 'http://stage.yunyunlive.cn/survey/start.php?uid=' + uid + '&cid=' + cid, // 分享链接
imgUrl: 'http://yunyunlive.oss-cn-beijing.aliyuncs.com/survey/title.jpg', // 分享图标
type: 'link', // 分享类型,music、video或link,不填默认为link
dataUrl: '', // 如果type是music或video,则要提供数据链接,默认为空
success: function () {
// 用户确认分享后执行的回调函数
// var sid = getQuery("sid");
// $.get("shared.php?sid=" + sid + "&type=1");
},
cancel: function () {
// 用户取消分享后执行的回调函数
}
});
//微信分享到朋友圈
wx.onMenuShareTimeline({
title: '七夕有奖趣味测试:测测你的撩汗指数,让你七夕不孤单!', // 分享标题
link: 'http://stage.yunyunlive.cn/survey/start.php?uid=' + uid + '&cid=' + cid, // 分享链接
imgUrl: 'http://yunyunlive.oss-cn-beijing.aliyuncs.com/survey/title.jpg', // 分享图标
success: function () {
// 用户确认分享后执行的回调函数
// var sid = getQuery("sid");
// $.get("shared.php?sid=" + sid + "&type=2");
},
cancel: function () {
// 用户取消分享后执行的回调函数
}
});
});
</script>
</body>
</html>