// video.js // videojs.options.flash = __uri('../node_modules/videojs-swf-saints/dist/video-js.swf'); // videojs.options.techorder = ['flash']; 'use strict'; var ismobile = /android|iphone|ipad|ipod/g.test(window.navigator.useragent.tolowercase()) || $(window).width() < 1024; var hasanimation = window.animationevent || window.webkitanimationevent; if (!hasanimation) { $('body, *[data-animation]').addclass('not-animation'); } // 获取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); $('*[data-full]').css('height', $(window).height()); $('*[data-accordion]').each(function () { $(this).find('> *').hover(function () { $(this).addclass('show').removeclass('hide').siblings().addclass('hide').removeclass('show'); }, function () { $(this).removeclass('hide').removeclass('show').siblings().removeclass('hide').removeclass('show'); }); }); $('*[data-count-up-target]').each(function () { var numanim = new countup(this, 0, 0, 0, 2); numanim.start(); $(this).data('countup', numanim); }); $(window).bind('scroll', setshow); setshow(); function setshow() { var shows = $('*[data-show]'); var scrolltop = $(window).scrolltop(); var wh = $(window).height(); shows.each(function () { if ($(this).offset().top - scrolltop - wh <= 0 && !$(this).hasclass('data-showed')) { $(this).addclass('show').addclass('data-showed'); if ($(this).attr('data-show')) { (function () { eval($(this).attr('data-show')); }).bind(this)(); } } }); if (ismobile) { shows.addclass('show'); } } //初始化hammer fn $.fn.hammer = function (opt) { if (/msie/g.test(window.navigator.useragent.tolowercase())) { var _this = this; return { on: function on(method, callback) { $(_this).on('click', callback); } }; } else { if (!this.length) { return { on: function on() {} }; } return new hammer(this.get(0), opt || {}); } }; // 修复active伪类无效 $('body').on('touchstart', function () {}); // fastclick $(function () { fastclick.attach(document.body); }); $('#totop').hammer().on('tap', function () { $('html, body').animate({ scrolltop: 0 }); }); // 设置导航背景 function setnavbg() { var top = $(window).scrolltop(); if (top > $('*[data-show-menu]').outerheight() - $('.header').outerheight()) { $('.header, .mobile-header, *[data-follow]').addclass('black'); } else { $('.header, .mobile-header, *[data-follow]').removeclass('black'); } // $('.header-space').height($('.header').outerheight()); // settimeout(() => { // $('.header-space').height($('.header').outerheight()); // }, 350); settop(); if ($(window).width() <= 320) { $('body').addclass('w320'); } else { $('body').removeclass('w320'); } } 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(); // 移动端菜单 $('.mobile-side-menu li.sub > i, .mobile-side-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-side-menu').toggleclass('show'); }); $('.mobile-side-menu .close').hammer().on('tap', function () { $('.mobile-side-menu').toggleclass('show'); }); $('.mobile-side-menu .left').hammer().on('tap', function () { $('.mobile-side-menu').toggleclass('show'); }); // 绑定视频播放弹出播放事件 var videoarray = []; var videojskey = 'data-videojs-id'; var videotpl = '
' + '
' + '' + '
×
' + '
' + '
'; $('*[data-video-url]').each(function () { $(this).click(function () { var id = parseint($(this).attr(videojskey)); if (!isnan(id)) { videoarray[id].video.play(); if (!ismobile) { videoarray[id].container.addclass('show'); } return; } var url = $(this).attr('data-video-url'); var video = $(videotpl); video.find('source').attr('src', url); $('body').append(video); video.find('.close').on('click', hidevideodialog); videoarray.push({ container: video, video: videojs('my-player') }); video.attr('video-index', videoarray.length - 1); $(this).attr(videojskey, videoarray.length - 1); settimeout(function () { if (!ismobile) { video.addclass('show'); } // videoarray[parseint(video.attr('video-index'), 10)].video.play(); }, 300); }); }); function hidevideodialog() { $(this).parents('.video-dialog').removeclass('show'); videoarray[parseint($(this).parents('.video-dialog').attr('video-index'), 10)].video.pause(); } // 查看大图 bindgallery(); 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')); blueimp.gallery(data, { container: '#blueimp-gallery', carousel: true, hidepagescrollbars: true, disablescroll: true }); }); }); }