main.js 9.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280
  1. $(window).on("load",function(){
  2. //获取页面url后面的参数
  3. var number = function(variable) {
  4. var query = window.location.search.substring(1);
  5. var vars = query.split("&");
  6. for (var i=0;i<vars.length;i++) {
  7. var pair = vars[i].split("=");
  8. if(pair[0] == variable){return pair[1];}
  9. }
  10. return(false);
  11. };
  12. var HotContent = function(url){
  13. this.screenHeight = $(document.body).height() * 0.6;
  14. this.url = url;
  15. this.data = null;
  16. this.wrap = {
  17. images: "wrap-img",
  18. video: "wrap-video",
  19. model: "wrap-model",
  20. iframe: "wrap-iframe"
  21. }
  22. this.ajax();
  23. };
  24. HotContent.prototype.ajax = function(){
  25. var that = this;
  26. $.ajax({
  27. url:that.url,
  28. dataType: "json",
  29. success: function (data) {
  30. that.data = data;
  31. that.init();
  32. //移动端自动播放
  33. setTimeout(function() {
  34. parent.loaddingSuccess && parent.loaddingSuccess();
  35. }, 16)
  36. },
  37. error: function (msg) {
  38. console.log("错误:"+msg);
  39. }
  40. })
  41. };
  42. HotContent.prototype.init = function(){
  43. var num = number("m");
  44. this.data[num].images ? this.createElements(this.data[num].images,this.wrap.images) : '';
  45. this.data[num].video ? this.createElements(this.data[num].video,this.wrap.video) : '';
  46. this.data[num].model ? this.createElements(this.data[num].model,this.wrap.model) : '';
  47. this.data[num].iframe ? this.createElements(this.data[num].iframe,this.wrap.iframe) : '';
  48. this.footer();
  49. this.onlyType();
  50. //加载视频
  51. $.getScript("js/vedio.js");
  52. //默认初始化显示的类型
  53. this.InitialDefaultDisplay($(".footer-btn > button:first").attr("data-name"));
  54. var that = this;
  55. $(".footer-btn > button").on("click",function(){
  56. that.InitialDefaultDisplay($(this).attr("data-name"));
  57. });
  58. $(".o-slider-header img").on("pointerdown",function(e){
  59. e.preventDefault();
  60. })
  61. };
  62. HotContent.prototype.InitialDefaultDisplay = function(id){
  63. $("."+id).show().siblings().hide();
  64. $('[data-name='+id+']').addClass("active").siblings().removeClass("active");
  65. if($("."+id).find("video").length < 1){
  66. if($("."+id).siblings().find("video").length > 0)$("."+id).siblings().find("video")[0].pause();
  67. $(".playPause").addClass("fa-play").removeClass("fa-pause");
  68. }
  69. };
  70. HotContent.prototype.createElements = function(data,classname){
  71. var contioner = $(".contioner");
  72. function createChildrenElements(){
  73. var children = [];
  74. switch (classname) {
  75. case this.wrap.images:
  76. data.forEach(function(currentValue){ children.push('<img src='+currentValue+' alt=图片 />') ; })
  77. break;
  78. case this.wrap.video:
  79. data.forEach(function(currentValue){ children.push(videoEle(currentValue.url,currentValue.img)); })
  80. break;
  81. case this.wrap.model:
  82. data.forEach(function(currentValue){ children.push('<iframe src='+currentValue+' ></iframe>'); })
  83. break;
  84. case this.wrap.iframe:
  85. data.forEach(function(currentValue){ children.push('<iframe src='+currentValue+' ></iframe>'); })
  86. break;
  87. }
  88. return children;
  89. }
  90. function videoEle(src,img){
  91. if(/Android|webOS|iPhone|iPod|BlackBerry/i.test(navigator.userAgent)){
  92. return '<div class="video-index" >\
  93. <div class="js-video">\
  94. <video class="js-media" poster='+img+' webkit-playsinline="true" x-webkit-airplay="true" playsinline="true" >\
  95. <source src='+src+' type="video/mp4" />\
  96. <p>你的浏览器不支持 HTML5 Video。</p>\
  97. </video>\
  98. <i data-playPause class="playPause fa ui-icon">\
  99. <span></span>\
  100. <div class="ui-icon-before">\
  101. <div class="ui-icon-after"></div>\
  102. </div>\
  103. </i>\
  104. <div class="ui">\
  105. <div>\
  106. <span class="timeDisplay"><i data-currentTime>0:00</i> / <i data-duration>0:00</i></span>\
  107. </div>\
  108. <div>\
  109. <div data-progress class="progress">\
  110. <div data-buffer class="progress-buffer"></div>\
  111. <div data-time class="progress-time"></div>\
  112. </div><!-- progress -->\
  113. </div>\
  114. <div>\
  115. <div data-mute class="fa fa-volume-up ui-icon">\
  116. </div>\
  117. </div>\
  118. <div>\
  119. <div data-volume="100" class="volumeControl"><span class="ui-slider-handle"></span></div>\
  120. </div>\
  121. </div>\
  122. <i data-fullscreen class="fullscreen iconicfill-fullscreen" title="fullscreen"></i>\
  123. </div>\
  124. </div>';
  125. }else{
  126. return '<video src='+src+' controls="controls" autoplay poster='+img+'></video>'
  127. }
  128. }
  129. function singleElement(){
  130. var SE = createChildrenElements.call(this);
  131. contioner.append('<div class='+classname+'>'+SE+'</div>').css("height",this.screenHeight);
  132. this.Zoom(classname);
  133. };
  134. function doubleElement(){
  135. var DE = createChildrenElements.call(this);
  136. var _doubleElement = this.generateElements().mainElements(classname,this.generateElements(data,DE).multiElement());
  137. contioner.append(_doubleElement).css("height",this.screenHeight);
  138. this.build(classname);
  139. this.Zoom(classname);
  140. };
  141. if(data.length > 1)
  142. {
  143. doubleElement.call(this,classname);
  144. }
  145. else
  146. {
  147. singleElement.call(this,classname);
  148. }
  149. };
  150. HotContent.prototype.generateElements = function(data,ele){
  151. function combination(SingleOriginal){
  152. if(!data) return;
  153. return '<div class="o-slider--item" >\
  154. <div class="o-slider-bg">\
  155. <div class="o-slider-header" >'
  156. +SingleOriginal+
  157. '</div>\
  158. </div>\
  159. </div>';
  160. }
  161. return {
  162. mainElements : function(classname,children){
  163. return '<div class='+classname+'>\
  164. <div class="o-sliderContainer" id=pbSliderWrap-'+classname+'>\
  165. <div class="o-slider" id=pbSlider-'+classname+'>'
  166. +children+
  167. '</div>\
  168. </div>\
  169. </div>';
  170. },
  171. multiElement : function(){
  172. var _multiElement = "";
  173. for (var i = 0; i < data.length; i++) {
  174. _multiElement += combination(ele[i]);
  175. }
  176. return _multiElement;
  177. }
  178. };
  179. };
  180. //启动轮播
  181. HotContent.prototype.build = function(id) {
  182. var screenHeight = this.screenHeight;
  183. $('#pbSlider-'+id).pbTouchSlider({
  184. slider_Wrap: '#pbSliderWrap-'+id,
  185. slider_Threshold: 10,
  186. slider_Speed:600,
  187. slider_Ease:'ease-out',
  188. slider_Drag : true,
  189. slider_Arrows: {
  190. enabled : true
  191. },
  192. slider_Dots: {
  193. class :'.o-slider-pagination',
  194. enabled : true,
  195. preview : false
  196. },
  197. slider_Breakpoints: {
  198. default: {
  199. height: screenHeight
  200. },
  201. tablet: {
  202. height: screenHeight,
  203. media: 1024
  204. },
  205. smartphone: {
  206. height: screenHeight,
  207. media: 768
  208. }
  209. }
  210. });
  211. };
  212. // 启动图片的放大缩小
  213. HotContent.prototype.Zoom = function(classname) {
  214. if(/Android|webOS|iPhone|iPod|BlackBerry/i.test(navigator.userAgent)){
  215. if(classname != "wrap-img") return;
  216. $("."+classname).find(".o-slider-header").each(function(){
  217. new RTP.PinchZoom(this, {});
  218. })
  219. }
  220. };
  221. HotContent.prototype.footer = function() {
  222. $(".footer").append(this.footerCreateEle());
  223. };
  224. HotContent.prototype.footerCreateEle = function() {
  225. var num = number("m");
  226. var lang = number("lang");
  227. var footerH3 = this.data[num].text ? lang == "en" ? this.data[num].text.EH.title : this.data[num].text.CH.title : "";
  228. var footerBtn = '';
  229. var btnIcon = {
  230. "img":["img-icon","图片"],
  231. "video":["video-icon","视频"],
  232. "model":["model-icon","3D"],
  233. "iframe":["iframe-icon","网页"]
  234. };
  235. function btnBuild(id,classname,text){
  236. return '<button data-name='+id+'><i class='+classname+'></i>'+text+'</button>'
  237. }
  238. function footerText(data){
  239. if(!data) return "";
  240. var text = '';
  241. var record = lang == "en" ? data.EH : data.CH ;
  242. record.content.forEach(function(currentValue) {
  243. text += "<p>"+currentValue+"</p>";
  244. });
  245. return text;
  246. }
  247. this.data[num].model ? footerBtn += btnBuild(this.wrap.model,btnIcon.model[0],btnIcon.model[1]) : '';
  248. this.data[num].video ? footerBtn += btnBuild(this.wrap.video,btnIcon.video[0],btnIcon.video[1]) : '';
  249. this.data[num].iframe ? footerBtn += btnBuild(this.wrap.iframe,btnIcon.iframe[0],btnIcon.iframe[1]): '';
  250. this.data[num].images ? footerBtn += btnBuild(this.wrap.images,btnIcon.img[0],btnIcon.img[1]) : '';
  251. return '<div class="footer-title"><h3>'+footerH3+'</h3><div class=footer-btn>'+footerBtn+'</div></div>\
  252. <div class=footer-text>'+footerText(this.data[num].text)+'<div class=footer-mask></div></div>';
  253. }
  254. HotContent.prototype.onlyType = function() {
  255. var footerBtn = $(".footer-btn");
  256. if(footerBtn.children().length > 1 ) return;
  257. footerBtn.hide();
  258. if(/Android|webOS|iPhone|iPod|BlackBerry/i.test(navigator.userAgent)){
  259. if(!this.data[number("m")].text ){
  260. $(".contioner").css("height",$(document.body).height() * 0.96);
  261. }
  262. $(".footer-btn").hide();
  263. }
  264. }
  265. new HotContent("https://super.4dage.com/data/"+number("id")+"/hot/js/data2.js");
  266. //new HotContent("http://192.168.0.41:8080/SuperTwo/data/"+number("id")+"/hot/js/data2.js");
  267. })