// video.js // videojs.options.flash = __uri('../node_modules/videojs-swf-saints/dist/video-js.swf'); // videojs.options.techOrder = ['flash']; "use strict"; var hasAni = false, animationstring = "animation", keyframeprefix = "", domPrefixes = "Webkit Moz O ms Khtml".split(" "), pfx = "", elm = document.createElement("div"); if (elm.style.animationName !== undefined) { hasAni = true; } if (hasAni === false) { for (var i = 0; i < domPrefixes.length; i++) { if (elm.style[domPrefixes[i] + "AnimationName"] !== undefined) { pfx = domPrefixes[i]; animationstring = pfx + "Animation"; keyframeprefix = "-" + pfx.toLowerCase() + "-"; hasAni = true; break; } } } console.log("hasAni", hasAni); if (!hasAni) { $("body").addClass("no-animation"); } var isMobile = /android|iphone|ipad|ipod/g.test(window.navigator.userAgent.toLowerCase()) || $(window).width() <= 1024; var isMac = /mac os x/g.test(window.navigator.userAgent.toLowerCase()); // 获取url传的参数,并赋值到searchParams $(function () { var search = window.location.search; var params = {}; if (search && /\?/g.test(search)) { search = search.split("?")[1]; } if (/&/g.test(search)) { search = search.split("&"); } else { search = [search]; } search.forEach(function (v, i, f) { if (/=/g.test(v)) { params[v.split("=")[0]] = v.split("=")[1]; } else { if (v) { params[v] = null; } } }); window.searchParams = params; }); // 获取url传的参数,并赋值到hashParams $(function () { function getHash() { var search = window.location.hash; var params = {}; if (search && /\#/g.test(search)) { search = search.split("#")[1]; } if (/&/g.test(search)) { search = search.split("&"); } else { search = [search]; } search.forEach(function (v, i, f) { if (/=/g.test(v)) { params[v.split("=")[0]] = v.split("=")[1]; } else { if (v) { params[v] = null; } } }); window.hashParams = params; return params; } getHash(); window.getHash = getHash; }); // hash 事件兼容 (function (window) { // 如果浏览器原生支持该事件,则退出 if ("onhashchange" in window.document.body) { return; } var location = window.location, oldURL = location.href, oldHash = location.hash; // 每隔100ms检测一下location.hash是否发生变化 setInterval(function () { var newURL = location.href, newHash = location.hash; // 如果hash发生了变化,且绑定了处理函数... if (newHash != oldHash && typeof window.onhashchange === "function") { // execute the handler window.onhashchange({ type: "hashchange", oldURL: oldURL, newURL: newURL }); oldURL = newURL; oldHash = newHash; } }, 100); })(window); //初始化hammer fn $.fn.hammer = function (opt) { var _this3 = this; var _this = this; if (/msie/g.test(window.navigator.userAgent.toLowerCase())) { return { on: function on(method, callback) { $(_this).on("click", callback); } }; } else { if (!this.length) { return { on: function on() {} }; } return { on: function on(type, fn) { if (_this.each) { _this.each(function () { new Hammer($(this).get(0), opt || {}).on(type, fn); }); } else { new Hammer($(_this3).get(0), opt || {}).on(type, fn); } } }; } }; // 修复active伪类无效 $("body").on("touchstart", function () {}); // fastclick $(function () { FastClick.attach(document.body); }); $("#toTop").hammer().on("tap", function () { $("html, body").animate({ scrollTop: 0 }); }); // 绑定header $(".header .nav > li").hover(function () { setHeaderUl(); }); function setHeaderUl() { var uls = $(".header .nav > li > ul"); uls.each(function () { var ul = $(this); var liw = $(this).parent().outerWidth(); var lis = $(this).find("li a"); var max = 0; lis.each(function () { if (max < $(this).outerWidth()) { max = $(this).outerWidth(); } }); if (max < liw) { max = liw; } ul.outerWidth(max); ul.css({ left: (liw - max) * 0.5 }); }); } setHeaderUl(); // 设置导航背景 var prevScrollTop = 0; function setNavBg() { var top = $(window).scrollTop(); var ww = $(window).width(); var wh = $(window).height(); if (prevScrollTop && !secondNavLock) { if (prevScrollTop > top || !$(".header.white").length) { $(".header.up-down-show").addClass("show"); } else { $(".header.up-down-show").removeClass("show"); } } prevScrollTop = top; updateSecondNav(); setSecondBannerVideo(); // if (top < 0) { // return; // } // if (top > document.body.scrollHeight - wh) { // return; // } if (!isMobile) { $("*[data-full-height]").outerHeight($(window).height()); } if (!$('body.pc[data-page="index"]').length) { var offset = ($(".second-banner").outerHeight() || 100) - 50; if (top > offset) { $(".header, .mobile-header").addClass("white"); $(".header, .mobile-header").addClass("bg-white"); setHeaderUl(); } else { $(".header, .mobile-header").removeClass("white"); $(".header, .mobile-header").removeClass("bg-white"); } } $(".header-space").height($(".header").height()); setTop(); if ($(window).width() <= 320) { $("body").addClass("w320"); } else { $("body").removeClass("w320"); } if (!isMobile) { $("*[scale-padding-top]").each(function () { var height = parseInt($(this).attr("scale-padding-top"), 10); var mw = $("body").width(); var unLimit = $(this).attr("scale-padding-top-unlimit") === "true"; var lw = 1920; if (mw > 1920) { mw = 1920; } if (ww > lw && !unLimit) { $(this).css("padding-top", height); } else if (ww < mw) { $(this).css("padding-top", mw / lw * height); } else if (ww >= 1920) { $(this).css("padding-top", ww / mw * height); } else { $(this).css("padding-top", ww / lw * height); } }); $("*[scale-padding]").each(function () { var height = parseInt($(this).attr("scale-padding"), 10); var mw = $("body").width(); var unLimit = $(this).attr("scale-padding-unlimit") === "true"; var lw = 1920; if (mw > 1920) { mw = 1920; } if (ww > lw && !unLimit) { $(this).css("padding", height); } else if (ww < mw) { $(this).css("padding", mw / lw * height); } else if (ww >= 1920) { $(this).css("padding", ww / mw * height); } else { $(this).css("padding", ww / lw * height); } }); $("*[scale-size]").each(function () { var height = parseInt($(this).attr("scale-size"), 10); var mw = $("body").width(); var unLimit = $(this).attr("scale-size-unlimit") === "true"; var lw = 1920; if (mw > 1920) { mw = 1920; } if (ww > lw && !unLimit) { $(this).outerHeight(height); } else if (ww < mw) { $(this).outerHeight(mw / lw * height); } else if (ww >= 1920) { $(this).outerHeight(ww / mw * height); } else { $(this).outerHeight(ww / lw * height); } }); $("*[scale-width]").each(function () { var height = parseInt($(this).attr("scale-width"), 10); var mw = $("body").width(); var unLimit = $(this).attr("scale-width-unlimit") === "true"; var lw = 1920; if (mw > 1920) { mw = 1920; } if (ww > lw && !unLimit) { $(this).css("width", height); } else if (ww < mw) { $(this).css("width", mw / lw * height); } else if (ww >= 1920) { $(this).css("width", ww / mw * height); } else { $(this).css("width", ww / lw * height); } }); $("*[scale-font-size]").each(function () { var height = parseInt($(this).attr("scale-font-size"), 10); var mw = $("body").width(); var unLimit = $(this).attr("scale-font-size-unlimit") === "true"; var lw = 1920; var scale = 1; if (ww < 1680) { if (height >= 30) { scale = 0.75; } else { scale = 0.85; } } if (ww < 1366) { if (height >= 30) { scale = 0.6; } else { scale = 0.7; } } if (mw > 1920) { mw = 1920; } if (ww >= lw && !unLimit) { $(this).css("fontSize", height); } else if (ww < mw) { // $(this).css("fontSize", (mw / lw) * height); $(this).css("fontSize", scale * height); } else if (ww >= 1920) { $(this).css("fontSize", ww / mw * height); } else { // $(this).css("fontSize", (ww / lw) * height); $(this).css("fontSize", scale * height); } }); $("*[scale-line-height]").each(function () { var height = parseInt($(this).attr("scale-line-height"), 10); var mw = $("body").width(); var unLimit = $(this).attr("scale-line-height-unlimit") === "true"; var lw = 1920; var scale = 1; if (ww < 1680) {} if (ww < 1366) { if (height >= 30) { scale = 0.75; } else { scale = 0.85; } } if (ww < 1280) { if (height >= 30) { scale = 0.7; } else { scale = 0.8; } } if (mw > 1920) { mw = 1920; } if (ww >= lw && !unLimit) { $(this).css("lineHeight", height + "px"); } else if (ww < mw) { // $(this).css("lineHeight", (mw / lw) * height + "px"); $(this).css("lineHeight", scale * height + "px"); } else if (ww >= 1920) { $(this).css("lineHeight", ww / mw * height + "px"); } else { // $(this).css("lineHeight", (ww / lw) * height + "px"); $(this).css("lineHeight", scale * height + "px"); } }); $("*[scale-scale]").each(function () { var height = parseInt($(this).attr("scale-scale"), 10) || 1; var mw = $("body").width(); var unLimit = $(this).attr("scale-scale-unlimit") === "true"; var lw = 1920; var convertScale = function convertScale(num) { var res = parseFloat(parseFloat(num).toFixed(1)); if (res * 10 % 2 === 1) { res += 0.1; } return res; }; if (mw > 1920) { mw = 1920; } if (ww > lw && !unLimit) { $(this).css("transform", "scale(" + height + ")"); } else if (ww < mw) { $(this).css("transform", "scale(" + convertScale(mw / lw * height) + ")"); } else if (ww >= 1920) { $(this).css("transform", "scale(" + convertScale(ww / mw * height) + ")"); } else { $(this).css("transform", "scale(" + convertScale(ww / lw * height) + ")"); } }); } updatePlatform(); updateAnimate(); // setTimeout(() => { // updateAnimate(); // }, 10); } function setTop() { var top = $("#toTop"); var scrollTop = $("body").scrollTop() || $("html").scrollTop(); var wh = $(window).height() * 0.5; if (scrollTop > wh) { top.addClass("show"); } else { top.removeClass("show"); } } $(window).on("scroll", setNavBg); $(window).on("resize", setNavBg); setNavBg(); $(document).ready(function () { setNavBg(); $("body").addClass("loaded"); }); // PC端搜索 $(".handle-header-search").on("click", function () { $(".header-search").toggleClass("show"); }); // 移动端菜单 $(".handle-search").hammer().on("tap", function () { $(".mobile-search").toggleClass("show"); }); $(" .handle-menu").hammer().on("tap", function () { $(".mobile-menu").toggleClass("show"); }); $(".mobile-menu li.sub > i, .mobile-menu li.sub > a").each(function () { var _this = this; $(_this).on("touchend", function (e) { e.stopPropagation(); $(_this).parent().toggleClass("expand"); }); }); $(".mobile-header .menu").hammer().on("tap", function () { $(".mobile-menu").toggleClass("show"); }); $(".mobile-menu .left").hammer().on("tap", function () { $(".mobile-menu").toggleClass("show"); }); function updateAnimate() { var selector = $(".show-in, .fade-in, .scale-in, .fade-in-up, .fade-in-left, .fade-in-right, .fade-in-down, *[count-up-to], *[count-up-to-p]"); var wh = $(window).height(); var st = $(window).scrollTop(); var offset = 0; var space = 150; selector.each(function () { var _this4 = this; var oft = $(this).offset().top - wh - st; var delay = parseInt($(this).attr("data-fade-delay"), 10) || 50; if (oft < 0 && !$(this).hasClass("show")) { $(this).attr("data-faded", true); if (oft > -wh) { offset += space; } setTimeout(function () { $(_this4).addClass("show"); window.animateShowCallback && animateShowCallback(_this4); if (!$('body[data-page="index"]').length) { if ($(_this4).attr("count-up-to")) { var to = parseInt($(_this4).attr("count-up-to")); var countUp = new CountUp(_this4, to, { separator: "" }); if (!countUp.error) { countUp.start(); } else { console.error(countUp.error); } } if ($(_this4).attr("count-up-to-p")) { var to = parseInt($(_this4).attr("count-up-to-p")); var countUp = new CountUp(_this4, to, { separator: "" }); if (!countUp.error) { countUp.start(); } else { console.error(countUp.error); } } } }, $(this).attr("data-fade-immediately") === "true" ? delay : delay + offset); } }); } function updatePlatform() { if (isMobile) { $("body").addClass("mobile").removeClass("pc"); } else { $("body").addClass("pc").removeClass("mobile"); } } if (isMobile) { setTimeout(function () { $(".mobile-menu").show(); }, 100); } $(window).on("resize", ifReload); function ifReload() { var _isMobile = /android|iphone|ipad|ipod/g.test(window.navigator.userAgent.toLowerCase()) || $(window).width() <= 1024; if (isMobile !== _isMobile) { window.location.reload(); } } // 绑定视频播放弹出播放事件 var videoArray = []; var videoJsKey = "data-videojs-id"; var videoTpl = '
' + '
' + '" + '
' + "
" + "
"; var videoTencentTpl = '
' + '
' + "{{tencent}}" + '
' + "
" + "
"; bindVideoDialog(); function bindVideoDialog() { $("*[data-video-url]").each(function () { if ($(this).attr("rendered")) return; $(this).attr("rendered", true); $(this).click(function () { var _this2 = this; var isFull = /ipad|iphone|ipod/g.test(navigator.userAgent.toLocaleLowerCase()); var type = $(this).attr("data-video-type"); var id = parseInt($(this).attr(videoJsKey)); if (type === "link") { window.open($(this).attr("data-video-url")); return; } if (type === "tencent") { var _ret = (function () { var video = $(videoTencentTpl.replace(/{{tencent}}/g, "")); $("body").append(video); video.find(".close").on("click", function () { $(this).parents(".video-dialog").remove(); }); setTimeout(function () { video.addClass("show"); }, 300); return { v: undefined }; })(); if (typeof _ret === "object") return _ret.v; } if (!isNaN(id)) { videoArray[id].video.play(); if (!isFull) { videoArray[id].container.addClass("show"); } return; } var url = $(this).attr("data-video-url"); var vid = "video_" + +new Date(); var video = $(videoTpl); video.find("video").attr("id", vid); video.find("source").attr("src", url); $("body").append(video); video.find(".close").on("click", hideVideoDialog); videoArray.push({ container: video, video: videojs(vid) }); video.attr("video-index", videoArray.length - 1); $(this).attr(videoJsKey, videoArray.length - 1); setTimeout(function () { if (!isFull) { video.addClass("show"); videoArray[parseInt(video.attr("video-index"), 10)].video.play(); } }, 300); if (isFull) { videoArray[parseInt(video.attr("video-index"), 10)].video.play(); } }); }); } function hideVideoDialog() { $(this).parents(".video-dialog").removeClass("show"); videoArray[parseInt($(this).parents(".video-dialog").attr("video-index"), 10)].video.pause(); } // 查看大图 bindGallery(); var galleryTemplate = "\n"; function bindGallery() { $("*[data-gallery]").each(function () { if ($(this).attr("data-bind") === "true") { return; } $(this).attr("data-bind", true).bind("click", function () { var data = eval($(this).attr("data-gallery")); var index = parseInt($(this).attr("data-gallery-index"), 10) || 0; $("#lightgallery-box").remove(); $("body").append(template.render(galleryTemplate, { list: data })); $("#lightgallery-box").lightGallery({ share: false }); $("#lightgallery-box").find("li").eq(index).trigger("click"); // blueimp.Gallery(data, { // container: '#blueimp-gallery', // carousel: true, // hidePageScrollbars: true, // disableScroll: true // }); }); }); } // 红色状态条计算,动画 if (!isMobile) { var activeBars = $(".has-active-bar"); activeBars.each(function () { var _this5 = this; var bar = $(''); var children = $(this).find("> *"); var firstChild = children.eq(0); var activeIndex = $(this).find("> .active").index(); var timer = undefined; var updateActiveBar = function updateActiveBar() { activeIndex = $(_this5).find("> .active").index(); setActive(activeIndex); }; $(this).data("bar", { updateActiveBar: updateActiveBar }); var setActive = function setActive(index) { var left = 0; var top = 0; for (var _i = 0; _i <= index; _i++) { left += children.eq(_i).outerWidth(); if (_i === index) { top = children.eq(_i).outerHeight(); left -= children.eq(_i).outerWidth() * 0.5; left -= bar.outerWidth() * 0.5; } } if (index < 0) { bar.hide(); } else { bar.show(); } bar.css({ transform: "translateX(" + left + "px)", top: top }); }; children.css("position", "relative"); firstChild.append(bar); setActive(activeIndex); children.hover(function () { clearTimeout(timer); setActive($(this).index()); }, function () { timer = setTimeout(function () { setActive(activeIndex); }, 150); }); }); } if (!isMobile) { $(".select").each(function () { var el = $('
'); var val = $('
'); $(this).find("select option").each(function (i) { var item = $("
" + $(this).text() + "
"); if (i === 0) { item.hide(); val.text(item.text()); } item.click(function () { $(this).parent().parent().find("select").val($(this).attr("data-value")); val.text(item.text()); item.hide().siblings().show(); }); el.append(item); }); val.insertBefore($(this).find(".arrow")); el.insertBefore($(this).find(".arrow")); }); $(".select").click(function (e) { e.stopPropagation(); $(this).toggleClass("focus"); $(this).parent().toggleClass("focus"); }); $("body").click(function () { $(".select").removeClass("focus"); $(".select").parent().removeClass("focus"); }); $(".header-search__body").click(function () { $(".select").removeClass("focus"); $(".select").parent().removeClass("focus"); }); } $(".modal .modal__close").on("click", function () { $(this).parent().removeClass("show"); }); var secondNavLock = false; $(".second-nav").each(function () { if (!$(this).find("ul li[data-target]").length) return; var _this = $(this); var setArrow = function setArrow() { if (_this.find(".second-nav__inner").scrollTop() > 0) { _this.find(".second-nav__inner").scrollTop(0); } console.log(_this.find(".second-nav__inner").get(0).scrollWidth, _this.find(".second-nav__inner").outerWidth()); if (_this.find(".second-nav__inner").get(0).scrollWidth <= _this.find(".second-nav__inner").outerWidth()) { _this.find(".mobile-arrow.right").addClass("hide"); _this.find(".mobile-arrow.left").addClass("hide"); } else if (_this.find(".second-nav__inner").scrollLeft() <= 10) { _this.find(".mobile-arrow.right").removeClass("hide"); _this.find(".mobile-arrow.left").addClass("hide"); } else if (_this.find(".second-nav__inner").scrollLeft() >= _this.find(".second-nav__inner").get(0).scrollWidth - _this.find(".second-nav__inner").outerWidth() - 10) { _this.find(".mobile-arrow.right").addClass("hide"); _this.find(".mobile-arrow.left").removeClass("hide"); } else { _this.find(".mobile-arrow.right").removeClass("hide"); _this.find(".mobile-arrow.left").removeClass("hide"); } }; $(this).find(".second-nav__inner").bind("scroll", setArrow); setArrow(); $(this).find(".mobile-arrow.right").click(function () { $(_this).find(".second-nav__inner").stop(true).animate({ scrollLeft: $(_this).find(".second-nav__inner").scrollLeft() + 150 }); }); $(this).find(".mobile-arrow.left").click(function () { $(_this).find(".second-nav__inner").stop(true).animate({ scrollLeft: $(_this).find(".second-nav__inner").scrollLeft() - 150 }); }); $(this).find("ul li").on("click", function () { $(this).addClass("active").siblings().removeClass("active"); $(this).parent().data("bar") && $(this).parent().data("bar").updateActiveBar(); $(".modal .modal__close").trigger("click"); $(".header.up-down-show").removeClass("show"); secondNavLock = true; $("html, body").animate({ scrollTop: $("*[data-target-content=\"" + $(this).data("target") + "\"]").offset().top - $(this).parents(".second-nav").outerHeight() - (isMobile ? $(".mobile-header").outerHeight() : 0) }); checkSecondNavCenter(); setTimeout(function () { secondNavLock = false; }, 600); }); }); function checkSecondNavCenter() { if (!$(".second-nav__inner").length) return; // if (!isMobile) return; $(".second-nav__inner").stop(true).animate({ scrollLeft: $(".second-nav ul li.active").offset().left + $(".second-nav__inner").scrollLeft() - $(".second-nav__inner").outerWidth() * 0.5 + $(".second-nav ul li.active").outerWidth() * 0.5 }); // $(".second-nav__inner").scrollLeft( // $(".second-nav ul li.active").offset().left + // $(".second-nav__inner").scrollLeft() - // $(".second-nav__inner").outerWidth() * 0.5 + // $(".second-nav ul li.active").outerWidth() * 0.5 // ); } function updateSecondNav() { if (secondNavLock) return; var contents = $("*[data-target-content]"); contents.each(function () { var scrollTop = $("html, body").scrollTop(); var offsetTop = $(this).offset().top - scrollTop; if (offsetTop > 0 & offsetTop < $(window).height() * 0.5) { $("*[data-target=\"" + $(this).attr("data-target-content") + "\"]").addClass("active").siblings().removeClass("active"); $("*[data-target=\"" + $(this).attr("data-target-content") + "\"]").parent().data("bar") && $("*[data-target=\"" + $(this).attr("data-target-content") + "\"]").parent().data("bar").updateActiveBar(); } }); checkSecondNavCenter(); } if (isMobile) { $(".footer .focus__icon").on("click", function () { if ($(this).attr("onclick")) return; $(this).toggleClass("active"); }); $(".footer .focus__icon .focus__icon__tooltip").on("click", function (e) { e.stopPropagation(); }); } // second banner vidoe if ($(".second-banner video").length && !isMobile) { $(".second-banner video").each(function () { $(this).attr("id", "bannerVideo"); var bannerVideo = videojs("bannerVideo"); bannerVideo.play(); }); } else { $(".second-banner video").remove(); } function setSecondBannerVideo() { if (!$(".second-banner video").length || isMobile) { return; } var ww = $(window).width(); var hh = $(".second-banner").outerHeight(); var video = $(".second-banner .video"); var width = 1936; var height = 624; width = hh / height * width; if (width < ww) { width = ww; } if (/MSIE/g.test(navigator.userAgent)) { video.outerWidth(width); } }