main.js 15 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364
  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 + "?m=" + new Date().getTime();
  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. window.parent.loaddingSuccess && window.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.data[num].backgroundMusic ? this.createAudio(this.data[num].backgroundMusic) : '';
  49. this.footer();
  50. this.onlyType();
  51. //加载视频
  52. $.getScript("js/vedio.js");
  53. //默认初始化显示的类型
  54. this.InitialDefaultDisplay($(".footer-btn > button:first").attr("data-name"));
  55. var that = this;
  56. $(".footer-btn > button").on("click", function () {
  57. that.InitialDefaultDisplay($(this).attr("data-name"));
  58. });
  59. //取消pc 鼠标滑动的时候出现的bug
  60. $(".o-slider-header img").on("mousedown", function (e) {
  61. e.preventDefault();
  62. window.move = false; // fyz 记录鼠标
  63. })
  64. };
  65. HotContent.prototype.InitialDefaultDisplay = function (id) {
  66. $("." + id).show().siblings().hide();
  67. $('[data-name=' + id + ']').addClass("active").siblings().removeClass("active");
  68. if ($("." + id).find("video").length < 1) {
  69. if ($("." + id).siblings().find("video").length > 0) $("." + id).siblings().find("video")[0].pause();
  70. }
  71. };
  72. HotContent.prototype.createAudio = function (url) {
  73. //20190923修改 ios 微信浏览器 iframe内 自动播放audio
  74. url='https://'+url.replace('https://','').replace('http://','')
  75. var _audio = '<audio id="HotBgMuisc" autoplay loop src='+url+'></audio>';
  76. $("body").append(_audio);
  77. var globalAudio=document.getElementById("HotBgMuisc");
  78. //ios其他浏览器需添加一个事件
  79. document.addEventListener("touchstart", function() {globalAudio.play()});//ios需要加个事件才能播放 不能自动播放;如果还有浏览器不行,换成别的交互事件
  80. function autoPlayAudio() {
  81. try {
  82. window.parent.wx.config({
  83. // 配置信息, 即使不正确也能使用 wx.ready
  84. debug: false,
  85. appId: '',
  86. timestamp: 1,
  87. nonceStr: '',
  88. signature: '',
  89. jsApiList: []
  90. });
  91. window.parent.wx.ready(function() {
  92. globalAudio.play();
  93. });
  94. } catch (error) {
  95. }
  96. };
  97. autoPlayAudio();
  98. };
  99. //创建主要的内容 图片 视频 网页 模型
  100. HotContent.prototype.createElements = function (data, classname) {
  101. var contioner = $(".contioner");
  102. function createChildrenElements() {
  103. var children = [];
  104. switch (classname) {
  105. case this.wrap.images:
  106. data.forEach(function (currentValue) {
  107. currentValue= currentValue.replace("http://",'').replace("https://",'')
  108. children.push('<img src=https://' + currentValue + ' alt=图片 />');
  109. })
  110. break;
  111. case this.wrap.video:
  112. data.forEach(function (currentValue) {
  113. currentValue.url= 'https://'+ currentValue.url.replace("http://",'').replace("https://",'')
  114. children.push(videoEle(currentValue.url, currentValue.img)); })
  115. break;
  116. case this.wrap.model:
  117. data.forEach(function (currentValue) { children.push('<iframe src=' + currentValue + ' ></iframe>'); })
  118. break;
  119. case this.wrap.iframe:
  120. data.forEach(function (currentValue) { children.push('<iframe src=' + currentValue + ' ></iframe>'); })
  121. break;
  122. }
  123. return children;
  124. }
  125. function videoEle(src, img) {
  126. if (/Android|webOS|iPhone|iPod|BlackBerry/i.test(navigator.userAgent)) {
  127. return '<div class="video-index" >\
  128. <div class="js-video">\
  129. <video class="js-media" poster='+ img + ' webkit-playsinline="true" x-webkit-airplay="true" playsinline="true" >\
  130. <source src='+ src + ' type="video/mp4" />\
  131. <p>你的浏览器不支持 HTML5 Video。</p>\
  132. </video>\
  133. <i data-playPause class="playPause fa ui-icon">\
  134. <span></span>\
  135. <div class="ui-icon-before">\
  136. <div class="ui-icon-after"></div>\
  137. </div>\
  138. </i>\
  139. <div class="ui">\
  140. <div>\
  141. <span class="timeDisplay"><i data-currentTime>0:00</i> / <i data-duration>0:00</i></span>\
  142. </div>\
  143. <div>\
  144. <div data-progress class="progress">\
  145. <div data-buffer class="progress-buffer"></div>\
  146. <div data-time class="progress-time"></div>\
  147. </div><!-- progress -->\
  148. </div>\
  149. <div>\
  150. <div data-mute class="fa fa-volume-up ui-icon">\
  151. </div>\
  152. </div>\
  153. <div>\
  154. <div data-volume="100" class="volumeControl"><span class="ui-slider-handle"></span></div>\
  155. </div>\
  156. </div>\
  157. <i data-fullscreen class="fullscreen iconicfill-fullscreen" title="fullscreen"></i>\
  158. </div>\
  159. </div>';
  160. } else {
  161. return '<video src=' + src + ' controls="controls" autoplay poster=' + img + '></video>'
  162. }
  163. }
  164. function singleElement() {
  165. var SE = createChildrenElements.call(this);
  166. contioner.append('<div class=' + classname + '><div class="o-slider-header">' + SE + '</div></div>').css("height", this.screenHeight);
  167. // if (window.parent.MP_PREFETCHED_MODELDATA ) {
  168. // if(window.parent.MP_PREFETCHED_MODELDATA.hotImageScale) {
  169. // contioner.find('img').each(function(index, elem) {
  170. // elem.addEventListener('click', hotImgDown(elem), false);
  171. // elem.addEventListener('mousemove', hotImgMove(elem), false);
  172. // elem.addEventListener('mouseup', hotImgUp(elem), false);
  173. // })
  174. // }
  175. // }
  176. this.Zoom(classname);
  177. };
  178. function doubleElement() {
  179. var DE = createChildrenElements.call(this);
  180. var _doubleElement = this.generateElements().mainElements(classname, this.generateElements(data, DE).multiElement());
  181. contioner.append(_doubleElement).css("height", this.screenHeight).attr("title","点击图片放大缩小");
  182. // if (window.parent.MP_PREFETCHED_MODELDATA ) {
  183. // if(window.parent.MP_PREFETCHED_MODELDATA.hotImageScale) {
  184. // contioner.find('img').each(function(index, elem) {
  185. // elem.addEventListener('click', hotImgDown(elem), false);
  186. // elem.addEventListener('mousemove', hotImgMove(elem), false);
  187. // elem.addEventListener('mouseup', hotImgUp(elem), false);
  188. // })
  189. // }
  190. // }
  191. this.build(classname);
  192. this.Zoom(classname);
  193. };
  194. function hotImgDown(elem){
  195. // console.log(1)
  196. return function(e){
  197. // window.move = false;
  198. }
  199. }
  200. function hotImgMove(elem){
  201. return function(){
  202. window.move = true;
  203. console.log(1);
  204. }
  205. }
  206. function hotImgUp(elem){
  207. return function(){
  208. if(window.move) return;
  209. if(elem.scale) { // 图片已放大
  210. // elem.style.maxHeight = '100%';
  211. elem.classList.remove('hotImageClick');
  212. elem.scale = false;
  213. }else{
  214. // elem.style.maxHeight = '130%';
  215. elem.classList.add('hotImageClick');
  216. elem.scale = true;
  217. }
  218. }
  219. }
  220. if (data.length > 1) {
  221. doubleElement.call(this, classname);
  222. }
  223. else {
  224. singleElement.call(this, classname);
  225. }
  226. };
  227. HotContent.prototype.generateElements = function (data, ele) {
  228. function combination(SingleOriginal) {
  229. if (!data) return;
  230. return '<div class="o-slider--item" >\
  231. <div class="o-slider-bg">\
  232. <div class="o-slider-header" >'
  233. + SingleOriginal +
  234. '</div>\
  235. </div>\
  236. </div>';
  237. }
  238. return {
  239. mainElements: function (classname, children) {
  240. return '<div class=' + classname + '>\
  241. <div class="o-sliderContainer" id=pbSliderWrap-'+ classname + '>\
  242. <div class="o-slider" id=pbSlider-'+ classname + '>'
  243. + children +
  244. '</div>\
  245. </div>\
  246. </div>';
  247. },
  248. multiElement: function () {
  249. var _multiElement = "";
  250. for (var i = 0; i < data.length; i++) {
  251. _multiElement += combination(ele[i]);
  252. }
  253. return _multiElement;
  254. }
  255. };
  256. };
  257. //启动轮播
  258. HotContent.prototype.build = function (id) {
  259. var screenHeight = this.screenHeight;
  260. $('#pbSlider-' + id).pbTouchSlider({
  261. slider_Wrap: '#pbSliderWrap-' + id,
  262. slider_Threshold: 10,
  263. slider_Speed: 600,
  264. slider_Ease: 'ease-out',
  265. slider_Drag: true,
  266. slider_Arrows: {
  267. enabled: true
  268. },
  269. slider_Dots: {
  270. class: '.o-slider-pagination',
  271. enabled: true,
  272. preview: false
  273. },
  274. slider_Breakpoints: {
  275. default: {
  276. height: screenHeight
  277. },
  278. tablet: {
  279. height: screenHeight,
  280. media: 1024
  281. },
  282. smartphone: {
  283. height: screenHeight,
  284. media: 768
  285. }
  286. }
  287. });
  288. };
  289. // 启动图片的放大缩小
  290. HotContent.prototype.Zoom = function (classname) {
  291. // if(/Android|webOS|iPhone|iPod|BlackBerry/i.test(navigator.userAgent)){
  292. // if(classname != "wrap-img") return;
  293. // $("."+classname).find(".o-slider-header").each(function(){
  294. // new RTP.PinchZoom(this, {});
  295. // })
  296. // }
  297. if (true) {
  298. if (classname != "wrap-img") return;
  299. $("." + classname).find(".o-slider-header").each(function () {
  300. new RTP.PinchZoom(this, {});
  301. })
  302. }
  303. };
  304. HotContent.prototype.footer = function () {
  305. $(".footer").append(this.footerCreateEle());
  306. };
  307. HotContent.prototype.footerCreateEle = function () {
  308. var num = number("m");
  309. var footerH3 = this.data[num].title || "";
  310. var footerText = this.data[num].content || "";
  311. var footerBtn = "";
  312. var btnIcon = {
  313. "img": ["img-icon", "图片"],
  314. "video": ["video-icon", "视频"],
  315. "model": ["model-icon", "3D"],
  316. "iframe": ["iframe-icon", "网页"]
  317. };
  318. function btnBuild(id, classname, text) {
  319. return '<button data-name=' + id + '><i class=' + classname + '></i>' + text + '</button>'
  320. }
  321. this.data[num].model ? footerBtn += btnBuild(this.wrap.model, btnIcon.model[0], btnIcon.model[1]) : '';
  322. this.data[num].video ? footerBtn += btnBuild(this.wrap.video, btnIcon.video[0], btnIcon.video[1]) : '';
  323. this.data[num].iframe ? footerBtn += btnBuild(this.wrap.iframe, btnIcon.iframe[0], btnIcon.iframe[1]) : '';
  324. this.data[num].images ? footerBtn += btnBuild(this.wrap.images, btnIcon.img[0], btnIcon.img[1]) : '';
  325. return '<div class="footer-title"><h3>' + footerH3 + '</h3><div class=footer-btn>' + footerBtn + '</div></div>\
  326. <div class=footer-text>'+ footerText + '<div class=footer-mask></div></div>';
  327. }
  328. HotContent.prototype.onlyType = function () {
  329. var footerBtn = $(".footer-btn");
  330. if (footerBtn.children().length > 1) return;
  331. footerBtn.hide();
  332. if (/Android|webOS|iPhone|iPod|BlackBerry/i.test(navigator.userAgent)) {
  333. if (!this.data[number("m")].content || !this.data[number("m")].title) {
  334. $(".contioner").css("height", $(document.body).height() * 0.96);
  335. }
  336. $(".footer-btn").hide();
  337. }
  338. }
  339. new HotContent("https://super.4dage.com/data/" + number("id") + "/hot/js/data.js");
  340. //new HotContent("http://192.168.0.41:8080/SuperTwo/data/"+number("id")+"/hot/js/data.js");
  341. })