-
Notifications
You must be signed in to change notification settings - Fork 0
/
showH5.js
162 lines (159 loc) · 7.46 KB
/
showH5.js
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
(function(globle){
var showH5 = (function(){
return{
num: 1,
total : $(".page").length,
audio : undefined,
initHtml : function (){ //初始化class
var AnimateImg = $($(".page" + this.num)).find(".animated");
$(AnimateImg).each(function(index, value){
var animationStyle = $(this).data("class");
$(this).removeClass(animationStyle);
})
},
next : function(){
if(this.num < this.total){
$(".page" + this.num).addClass("fadeOut hide");
this.initHtml();
this.num++;
this.setAnimation(this.num);
}
},
last : function(){
if(this.num > 1){
$(".page" + this.num).addClass("fadeOut hide");
this.initHtml();
this.num--;
this.setAnimation(this.num);
}
},
setAnimation : function(pageNum){
$(".page" + pageNum).removeClass("fadeOut hide");
var AnimateImg = $(".page" + pageNum).find(".animated");
$(AnimateImg).each(function(index, value){
var animationStyle = $(this).data("class");
var animationDelay = $(this).data("delay");
$(this).addClass(animationStyle).css({
"animation-delay":animationDelay,
"-webkit-animation-delay":animationDelay
});
})
},
loadImg : function(){
var totalNum = 0;
var jiazai = 0;
var imgs = document.getElementsByTagName("img");
var imgLen = imgs.length;
function setBaiNum(bai){
$("#baifen_txt").text(bai);
if(bai == 100){
setTimeout(function(){
$(".p1_close").addClass('hide');
showH5.setAnimation(1);
}, 500);
}
}
for(var i = 0; i < imgLen; i++){
if(imgs[i].complete){
jiazai++;
var baifenbi = Math.floor(jiazai/imgLen*100);
setBaiNum(baifenbi);
continue;
}
imgs[i].onload = function(){
jiazai++;
var baifenbi = Math.floor(jiazai/imgLen*100);
setBaiNum(baifenbi);
}
}
},
IsPC : function (){
var userAgentInfo = navigator.userAgent;
var Agents = ["Android", "iPhone", "SymbianOS", "Windows Phone", "iPad", "iPod"];
var flag = true;
for (var v = 0; v < Agents.length; v++) {
if (userAgentInfo.indexOf(Agents[v]) > 0) {
flag = false;
break;
}
}
return flag;
},
toPage: function(num){
$(".page" + this.num).addClass('hide');
showH5.initHtml(this.num-1, $(".page" + this.num));
showH5.setAnimation(num);
showH5.num = num;
},
AnimationEnd : function(div){
var divParent = $(div + "_parent");
var AnimateClass = $(divParent).data('class');
$(document).on("webkitAnimationEnd", div, function(e){
$(divParent).addClass(AnimateClass);
})
},
autoView : function (userAgent){
var screen_w=parseInt(window.screen.width),scale=screen_w/640;
var head = document.getElementsByTagName('head')[0];
if(/Android (\d+\.\d+)/.test(userAgent)){
var version=parseFloat(RegExp.$1);
head.innerHTML+=(version>2.3?'<meta id="auto_view" name="viewport" content="width=640, initial-scale = '+scale+',user-scalable=1, minimum-scale = '+scale+', maximum-scale = '+scale+', target-densitydpi=device-dpi">':'<meta name="viewport" content="width=640, target-densitydpi=device-dpi">');
}else{
head.innerHTML+=('<meta id="auto_view" name="viewport" content="width=640, initial-scale = '+scale+' ,minimum-scale = '+scale+', maximum-scale = '+scale+', user-scalable=no, target-densitydpi=device-dpi">');
};
},
viewResize : function(){
var screen_w=parseInt(window.screen.width),scale=screen_w/640;
$("#auto_view").attr("content","width=640, initial-scale = "+scale+",user-scalable=1, minimum-scale = "+scale+", maximum-scale = "+scale);
if(showH5.IsPC()){
document.body.style.margin = "0px auto";
}
},
autoPlayAudio : function (music_src) {
this.playmusic(music_src);
try{
WeixinJSBridge.invoke('getNetworkType', {}, function(e) {
var audio = document.getElementById('theaudio');
audio.play();
});
} catch(err){
console.log(err);
}
},
playmusic : function(music_src){
$('.Vbody').append('<div id="audiobox"><span id="radmark"></span><p class="icon-music" id="start"></p></div>');
var audio = document.createElement("audio");
audio.id = 'theaudio';
audio.loop = 'loop';
audio.autoplay='autoplay';
audio.src = music_src;
this.audio = audio;
$('#audiobox').append(audio);
$('#start').addClass('rotate');
$('#start').bind('tap',function(){
showH5.playOrPaused();
});
},
playOrPaused : function (){
if(this.audio.paused){
this.audio.play();
$('#start').addClass('rotate');
$('#radmark').addClass('radmark-show');
$('#radmark').html('播放');
setTimeout(function(){ $('#radmark').removeClass('radmark-show'); },1000);
return;
}
this.audio.pause();
$('#start').removeClass('rotate');
$('#radmark').addClass('radmark-show');
$('#radmark').html('暂停');
setTimeout(function(){ $('#radmark').removeClass('radmark-show'); },1000);
}
}
})();
globle.showH5 = showH5;
showH5.autoView(navigator.userAgent);
window.addEventListener("load", function(){
showH5.total = $(".page").length;
})
})(this);