base.js 63 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200120112021203120412051206120712081209121012111212121312141215121612171218121912201221122212231224122512261227122812291230123112321233123412351236123712381239124012411242124312441245124612471248124912501251125212531254125512561257125812591260126112621263126412651266126712681269127012711272127312741275127612771278127912801281128212831284128512861287128812891290129112921293129412951296129712981299130013011302
  1. /*根据屏幕适配font-size*/
  2. ;(function (doc, win) {
  3. var docEl = doc.documentElement,
  4. resizeEvt = 'onorientationchange' in window ? 'onorientationchange' : 'resize',
  5. recalc = function () {
  6. var clientWidth = docEl.clientWidth;
  7. if (!clientWidth) return;
  8. if(clientWidth>=750){
  9. docEl.style.fontSize = '100px';//屏幕大于750,font-size:100px;
  10. }else{
  11. docEl.style.fontSize = 100 * (clientWidth / 750) + 'px';
  12. }
  13. };
  14. setTimeout(function(){console.log($('header').height());},1);
  15. if (!doc.addEventListener) return;
  16. win.addEventListener(resizeEvt, recalc, false);
  17. doc.addEventListener('DOMContentLoaded', recalc, false);
  18. })(document, window);
  19. /*
  20. author : zhcool;
  21. date : 2018/5/15;
  22. version : v0.0.3;
  23. */
  24. ;(function($, window, document,undefined) {
  25. "use strict";
  26. var Tfn = function() {
  27. this.header = $('header'),
  28. this.center = $('#wrapper'),
  29. this.footer = $('footer'),
  30. this.author = 'zhcool',
  31. this.windowWidth = ('innerWidth' in window) ? window.innerWidth : document.documentElement.clientWidth,//屏幕宽度
  32. this.windowHeight = ('innerHeight' in window) ? window.innerHeight : document.documentElement.clientHeight,//屏幕高度
  33. this.IEnum = null;//如果是ie浏览器,ie的版本数
  34. this.isAnimating = false,//判断轮播动画是否进行中
  35. this.isAnimating1 = false,//判断下拉动画是否进行中
  36. this.aniTime = 600, //动画时间
  37. this.isPc = null,//是否为pc端
  38. this.rowNode = [],//页面块节点存储
  39. this.appDirection = null,//手机端触摸滑动方向
  40. this.support = { animations : Modernizr.cssanimations },//是否支持1,animations
  41. this.animEndEventNames = {
  42. 'WebkitAnimation' : 'webkitAnimationEnd',
  43. 'OAnimation' : 'oAnimationEnd',
  44. 'msAnimation' : 'MSAnimationEnd',
  45. 'animation' : 'animationend'
  46. },
  47. this.animEndEventName = this.animEndEventNames[ Modernizr.prefixed( 'animation' ) ],
  48. this.onEndAnimation = function( el, callback ) {//动画所属元素,如果不支持animations回调函数。
  49. var self = this;
  50. var onEndCallbackFn = function( ev ) {
  51. if( self.support.animations ) {
  52. if( ev.target != this ) return;
  53. this.removeEventListener( self.animEndEventName, onEndCallbackFn );
  54. }
  55. if( callback && typeof callback === 'function' ) { callback.call(); }
  56. };
  57. if( self.support.animations ) {
  58. el.addEventListener( self.animEndEventName, onEndCallbackFn );
  59. }
  60. else {
  61. onEndCallbackFn();
  62. }
  63. };
  64. var transEndEventNames = {
  65. 'WebkitTransition' : 'webkitTransitionEnd',
  66. 'MozTransition' : 'transitionend',
  67. 'OTransition' : 'oTransitionEnd',
  68. 'msTransition' : 'MSTransitionEnd',
  69. 'transition' : 'transitionend'
  70. },
  71. this.transEndEventName = transEndEventNames[ Modernizr.prefixed('transition') ]; //transition结束事件
  72. };
  73. Tfn.prototype = {
  74. //初始化
  75. init : function() {
  76. var self = this;
  77. if (!!window.ActiveXObject || "ActiveXObject" in window){
  78. $('body').addClass("ie");
  79. this.IEnum = parseInt(navigator.appVersion.split(";")[1].replace(/[ ]/g, "").replace("MSIE",""));
  80. if(this.IEnum<9){
  81. alert("您的浏览器版本过低,请下载IE9及以上版本");return false;
  82. }else if(this.IEnum==9){
  83. $('body').addClass("ie9");
  84. }else if(this.IEnum==10){
  85. $('body').addClass("ie10");
  86. }else if(this.IEnum==11){
  87. $('body').addClass("ie11");
  88. }
  89. }
  90. this.scrolly();
  91. this.IsPC();
  92. // this.storage();
  93. this.contentInit();
  94. this.appNav();
  95. this.downMove();
  96. // imagesLoaded(document.querySelectorAll('img'), function () {
  97. // self.picMove();
  98. // self.webGl_picMove();
  99. // });
  100. // this.picCut();
  101. this.dialog();
  102. this.tabBox();
  103. this.video_setting();
  104. if(!this.isPc){
  105. // this.touchMove();
  106. this.fullMenu();
  107. }else{
  108. this.toTop();
  109. }
  110. },
  111. //transform滚动惯性视差(背景滚动视差)
  112. scrolly:function () {
  113. var defaults = {
  114. wrapper: '#scrolly',
  115. parent_move : true,//容器跟随惯性滚动
  116. targets : '.scrolly-el',
  117. bgParallax : false,//背景惯性滚动
  118. wrapperSpeed: 0.08,
  119. targetSpeed: 0.02,
  120. targetPercentage: 0.1
  121. };
  122. var requestAnimationFrame =
  123. window.requestAnimationFrame || window.mozRequestAnimationFrame ||
  124. window.webkitRequestAnimationFrame || window.msRequestAnimationFrame;
  125. window.requestAnimationFrame = requestAnimationFrame;
  126. var cancelAnimationFrame = window.cancelAnimationFrame || window.mozCancelAnimationFrame;
  127. var extend = function () {
  128. // Variables
  129. var extended = {};
  130. var deep = false;
  131. var i = 0;
  132. var length = arguments.length;
  133. // Merge the object into the extended object
  134. var merge = function (obj) {
  135. for (var prop in obj) {
  136. if (obj.hasOwnProperty(prop)) {
  137. extended[prop] = obj[prop];
  138. }
  139. }
  140. };
  141. // Loop through each object and conduct a merge
  142. for ( ; i < length; i++ ) {
  143. var obj = arguments[i];
  144. merge(obj);
  145. }
  146. return extended;
  147. };
  148. var scrolly = function(){
  149. this.Targets = [];
  150. this.TargetsLength = 0;
  151. this.wrapper = '';
  152. this.windowHeight = 0;
  153. this.wapperOffset = 0;
  154. };
  155. scrolly.prototype = {
  156. isAnimate: false,
  157. isResize : false,
  158. scrollId: "",
  159. resizeId: "",
  160. init : function(options){
  161. this.settings = extend(defaults, options || {});
  162. this.wrapper = document.querySelector(this.settings.wrapper);
  163. if(this.wrapper==="undefined"){
  164. return false;
  165. }
  166. this.targets = document.querySelectorAll(this.settings.targets);
  167. document.body.style.height = this.wrapper.clientHeight + 'px';
  168. this.windowHeight = window.clientHeight;
  169. this.attachEvent();
  170. this.apply(this.targets,this.wrapper);
  171. this.animate();
  172. this.resize();
  173. },
  174. apply : function(targets,wrapper){
  175. if(this.settings.parent_move){
  176. this.wrapperInit();
  177. }
  178. this.targetsLength = targets.length;
  179. for (var i = 0; i < this.targetsLength; i++) {
  180. var attr = {
  181. offset : targets[i].getAttribute('data-offset'),
  182. speedX : targets[i].getAttribute('data-speed-x'),
  183. speedY : targets[i].getAttribute('data-speed-Y'),
  184. percentage : targets[i].getAttribute('data-percentage'),
  185. horizontal : targets[i].getAttribute('data-v')
  186. };
  187. this.targetsInit(targets[i],attr);
  188. }
  189. },
  190. wrapperInit: function(){
  191. this.wrapper.style.width = '100%';
  192. this.wrapper.style.position = 'fixed';
  193. },
  194. targetsInit: function(elm,attr){
  195. this.Targets.push({
  196. elm : elm,
  197. offset : attr.offset ? attr.offset : 0,
  198. offsetTop : $(elm).offset().top,
  199. hei : $(elm).height(),
  200. horizontal : attr.horizontal ? attr.horizontal : 0,
  201. top : 0,
  202. left : 0,
  203. speedX : attr.speedX ? attr.speedX : 1,
  204. speedY : attr.speedY ? attr.speedY : 1,
  205. percentage :attr.percentage ? attr.percentage : 0
  206. });
  207. },
  208. scroll : function(){
  209. var scrollTopTmp = document.documentElement.scrollTop || document.body.scrollTop;
  210. this.scrollTop = document.documentElement.scrollTop || document.body.scrollTop;
  211. var offsetBottom = this.scrollTop + this.windowHeight;
  212. if(this.settings.parent_move){
  213. this.wrapperUpdate(this.scrollTop);
  214. }
  215. for (var i = 0; i < this.Targets.length; i++) {
  216. this.targetsUpdate(this.Targets[i]);
  217. }
  218. },
  219. animate : function(){
  220. this.scroll();
  221. this.scrollId = requestAnimationFrame(this.animate.bind(this));
  222. },
  223. wrapperUpdate : function(){
  224. this.wapperOffset += (this.scrollTop - this.wapperOffset) * this.settings.wrapperSpeed;
  225. this.wrapper.style.transform = 'translate3d(' + 0 + ',' + Math.round(-this.wapperOffset* 100) / 100 + 'px ,' + 0 + ')';
  226. },
  227. targetsUpdate : function(target){
  228. var wH = $(window).height();
  229. target.offsetTop = $(target.elm).offset().top;
  230. target.top += ((this.scrollTop - target.offsetTop + (wH-target.hei)/2) * Number(this.settings.targetSpeed) * Number(target.speedY) - target.top) * this.settings.targetPercentage;
  231. target.left += ((this.scrollTop - target.offsetTop + (wH-target.hei)/2) * Number(this.settings.targetSpeed) * Number(target.speedX) - target.left) * this.settings.targetPercentage;
  232. var targetOffsetTop = ( parseInt(target.percentage) - target.top - parseInt(target.offset) );
  233. var offsetY = Math.round(targetOffsetTop * -100) / 100;
  234. var offsetX = 0;
  235. if(target.horizontal){
  236. var targetOffsetLeft = ( parseInt(target.percentage) - target.left - parseInt(target.offset) );
  237. offsetX = Math.round(targetOffsetLeft * -100) / 100;
  238. }
  239. if(this.settings.bgParallax){
  240. if(target.horizontal){
  241. $(target.elm).css({backgroundPosition: offsetX +'px 50%'});
  242. }else{
  243. $(target.elm).css({backgroundPosition: '50% ' + offsetY + 'px'});
  244. }
  245. }else{
  246. target.elm.style.transform = 'translate3d(' + offsetX + 'px ,' + offsetY + 'px ,' + 0 +')';
  247. }
  248. },
  249. resize: function(){
  250. var self = this;
  251. self.windowHeight = (window.innerHeight || document.documentElement.clientHeight || 0);
  252. if( parseInt(self.wrapper.clientHeight) != parseInt(document.body.style.height)){
  253. document.body.style.height = self.wrapper.clientHeight + 'px';
  254. }
  255. self.resizeId = requestAnimationFrame(self.resize.bind(self));
  256. },
  257. attachEvent : function(){
  258. var self = this;
  259. window.addEventListener('resize',(function(){
  260. if(!self.isResize){
  261. cancelAnimationFrame(self.resizeId);
  262. cancelAnimationFrame(self.scrollId);
  263. self.isResize = true;
  264. setTimeout((function(){
  265. self.isResize = false;
  266. self.resizeId = requestAnimationFrame(self.resize.bind(self));
  267. self.scrollId = requestAnimationFrame(self.animate.bind(self));
  268. }),200);
  269. }
  270. }));
  271. }
  272. };
  273. window.scrolly = new scrolly();
  274. return scrolly;
  275. },
  276. //内容层min-height
  277. contentInit:function(){
  278. var self = this,
  279. minHeight =self.windowHeight - (self.header.height() + self.footer.height());
  280. self.center.css('min-height',minHeight+'px');
  281. $('[data-hei]').each(function(index,e){
  282. var wid=$(this).width(),
  283. hei=parseInt(wid*($(this).attr('data-hei')));
  284. $(this).css('height',hei+"px");
  285. });
  286. $("[data-ahref]").on('click',function () {
  287. var src = $(this).attr('data-ahref');
  288. var type = $(this).attr('data-target');
  289. if(type==1){
  290. window.open(src);
  291. }else{
  292. window.location.href=src;
  293. }
  294. });
  295. },
  296. // 浏览器版本
  297. version:function(){
  298. var explorer = window.navigator.userAgent ;
  299. if (explorer.indexOf("MSIE") >= 0||explorer.indexOf("Trident")>0 ) {
  300. if(explorer.indexOf("MSIE 5")>0||explorer.indexOf("MSIE 6")>0||explorer.indexOf("MSIE 7")>0||explorer.indexOf("MSIE 8")>0) {
  301. return 'LowerIEVersion';
  302. }else{
  303. return 'EdgeOrTrident';
  304. }
  305. }
  306. else if (explorer.indexOf("Maxthon") >= 0) {return 'Maxthon';}
  307. else if (explorer.indexOf("Firefox") >= 0) {return 'FireFox';}
  308. else if(explorer.indexOf("Chrome") >= 0){ return 'Chrome';}
  309. else if(explorer.indexOf("Opera") >= 0){ return 'Opera';}
  310. else if(explorer.indexOf("Safari") >= 0){ return 'Safari';}
  311. },
  312. // 网站标识
  313. uunn:function(){
  314. if(this.version()!='LowerIEVersion'&&this.version()=="Chrome") {
  315. console.log('%cUUNN+','display:block;padding: 0 50px;line-height: 76px;background:#f00;color: #fff; font-size: 40px;border-radius: 6px;')
  316. console.log('Powered by %cUUNN+%c brand creative vanguard.','color:#f00;font-weight: 900;','');
  317. console.log('Learn more about us \nplease visit %chttp://www.uunn.cn','text-decoration: underline;');
  318. }
  319. },
  320. //对sessionStorage的操作(只有第一次对浏览网站:有loading动画 )
  321. storage:function () {
  322. var self = this,
  323. loading = $('#loader'),
  324. stor = JSON.parse(sessionStorage.getItem('key')),
  325. info ={call:null};//对网站浏览次数存储
  326. if(stor==null){
  327. info.call=1;
  328. self.uunn();
  329. sessionStorage.setItem('key',JSON.stringify(info));
  330. }else{
  331. info.call=stor.call+1;
  332. sessionStorage.setItem('key',JSON.stringify(info));
  333. loading.remove();
  334. }
  335. },
  336. //判断是否为pc端
  337. IsPC:function(){
  338. var self = this;
  339. var userAgentInfo = navigator.userAgent;
  340. var Agents = new Array("Android", "iPhone", "SymbianOS", "Windows Phone", "iPad", "iPod");
  341. self.isPc = true;
  342. for (var v = 0; v < Agents.length; v++) {
  343. if (userAgentInfo.indexOf(Agents[v]) > 0) { self.isPc = false; break; }
  344. }
  345. return self.isPc;
  346. },
  347. //页面切换(针对setinterval)
  348. VisibilityChange:function ( gofn , backfn ) {
  349. var hiddenProperty = 'hidden' in document ? 'hidden' :
  350. 'webkitHidden' in document ? 'webkitHidden' :
  351. 'mozHidden' in document ? 'mozHidden' :
  352. null;
  353. var visibilityChangeEvent = hiddenProperty.replace(/hidden/i, 'visibilitychange');
  354. var onVisibilityChange = function(){
  355. if (!document[hiddenProperty]) {
  356. backfn.call();
  357. }else{
  358. gofn.call();
  359. }
  360. };
  361. document.addEventListener(visibilityChangeEvent, onVisibilityChange);
  362. },
  363. //手机菜单动画
  364. appNav: function(){
  365. var self = this,
  366. appNav = $('.app-nav'),
  367. getApp = appNav.find('.getAppNav'),
  368. appUl = appNav.find('ul'),
  369. appLi = appUl.find('li'),
  370. appDown = appLi.find('.child-nav'),
  371. appUlWid = appUl.attr('data-width'),
  372. showAni = appUl.attr('data-effect'),
  373. hideAni = appUl.attr('data-hideAni');
  374. appUl.css('width',(this.windowWidth*appUlWid)+'px');
  375. getApp.on('click',function(e){
  376. if(self.isAnimating1) return false;
  377. self.isAnimating1 = true;
  378. var isActive = $(this).hasClass('menuActive');
  379. $(this).toggleClass('menuActive');
  380. if(isActive){
  381. appLi.removeClass(showAni).addClass(hideAni);
  382. for(var i=0;i<appDown.length;i++){
  383. var _this = $(appDown[i]);
  384. if(_this.hasClass('on')){
  385. _this.removeClass('on');
  386. }
  387. }
  388. setTimeout(function(){
  389. appUl.hide();
  390. self.isAnimating1 = false;
  391. },self.aniTime);
  392. }else{
  393. appLi.removeClass(hideAni).addClass(showAni);
  394. appUl.show();
  395. setTimeout(function(){
  396. self.isAnimating1 = false;
  397. },self.aniTime);
  398. }
  399. });
  400. appLi.on('click',function (e) {
  401. if($(this).hasClass('child-Down')){
  402. var nav = $(this).find('.child-nav');
  403. for(var i=0;i<appDown.length;i++){
  404. var _this = $(appDown[i]);
  405. if(_this.hasClass('on')&&!_this.is(nav)){
  406. _this.removeClass('on');
  407. }
  408. }
  409. nav.toggleClass('on');
  410. }
  411. });
  412. },
  413. //单页menu
  414. fullMenu: function () {
  415. var self = this,
  416. menu_bg = $('.fullMenu'),
  417. ishave = menu_bg.length<=0 ? true : false;
  418. if(ishave) return false;
  419. var ShapeOverlays = function (opts) {
  420. var elm = opts.svg;
  421. var menu = opts.el;
  422. var aItem = opts.aItem,
  423. showAni = aItem.getAttribute('data-effect'),
  424. hideAni = aItem.getAttribute('data-hideAni');
  425. var aList = $(aItem).find('.menu-list');
  426. var path = elm.querySelectorAll('path');
  427. var numPoints = 2;
  428. var duration = 600;
  429. var delayPointsArray = [];
  430. var delayPointsMax = 0;
  431. var delayPerPath = 200;
  432. var timeStart = Date.now();
  433. var isOpened = false;
  434. var isAnimating = false;
  435. function toggle() {
  436. isAnimating = true;
  437. for (var i = 0; i < numPoints; i++) {
  438. delayPointsArray[i] = 0;
  439. }
  440. if (isOpened === false) {
  441. open();
  442. } else {
  443. close();
  444. }
  445. }
  446. function open() {
  447. isOpened = true;
  448. elm.classList.add('is-opened');
  449. timeStart = Date.now();
  450. renderLoop();
  451. }
  452. function close() {
  453. isOpened = false;
  454. elm.classList.remove('is-opened');
  455. timeStart = Date.now();
  456. renderLoop();
  457. }
  458. function updatePath(time) {
  459. var points = [];
  460. for (var i = 0; i < numPoints; i++) {
  461. var thisEase = isOpened ?
  462. (i == 1) ? ease.cubicOut : ease.cubicInOut:
  463. (i == 1) ? ease.cubicInOut : ease.cubicOut;
  464. points[i] = thisEase(Math.min(Math.max(time - delayPointsArray[i], 0) / duration, 1)) * 100
  465. }
  466. var str = '';
  467. str += (isOpened) ? `M 0 0 V ${points[0]} ` : `M 0 ${points[0]} `;
  468. for (var i = 0; i < numPoints - 1; i++) {
  469. var p = (i + 1) / (numPoints - 1) * 100;
  470. var cp = p - (1 / (numPoints - 1) * 100) / 2;
  471. str += `C ${cp} ${points[i]} ${cp} ${points[i + 1]} ${p} ${points[i + 1]} `;
  472. }
  473. str += (isOpened) ? `V 0 H 0` : `V 100 H 0`;
  474. return str;
  475. }
  476. function render() {
  477. if (isOpened) {
  478. for (var i = 0; i < path.length; i++) {
  479. path[i].setAttribute('d', updatePath(Date.now() - (timeStart + delayPerPath * i)));
  480. }
  481. } else {
  482. for (var i = 0; i < path.length; i++) {
  483. path[i].setAttribute('d', updatePath(Date.now() - (timeStart +delayPerPath * (path.length - i - 1))));
  484. }
  485. }
  486. }
  487. function renderLoop() {
  488. render();
  489. if (Date.now() - timeStart < duration + delayPerPath * (path.length - 1) + delayPointsMax) {
  490. requestAnimationFrame(
  491. function () {
  492. renderLoop();
  493. }
  494. );
  495. }
  496. else {
  497. isAnimating = false;
  498. }
  499. }
  500. menu.addEventListener('click',function () {
  501. if (isAnimating) {
  502. return false;
  503. }
  504. toggle();
  505. if (isOpened === true) {
  506. menu.classList.add('is-opened-navi');
  507. setTimeout(function () {
  508. aItem.classList.add('is-opened');
  509. },700);
  510. aList.removeClass(hideAni).addClass(showAni);
  511. } else {
  512. menu.classList.remove('is-opened-navi');
  513. aList.removeClass(showAni).addClass(hideAni);
  514. self.onEndAnimation(aList[aList.length-1],function(){
  515. aItem.classList.remove('is-opened');
  516. });
  517. }
  518. });
  519. };
  520. (function() {
  521. var elmHamburger = $('.full-menu_m')[0];
  522. var gNavItems = document.querySelector('.menu-item');
  523. var elmOverlay = document.querySelector('.shape-overlays');
  524. new ShapeOverlays({
  525. svg : elmOverlay,
  526. el :elmHamburger,
  527. aItem:gNavItems
  528. });
  529. })();
  530. },
  531. //下拉动画
  532. downMove:function(){
  533. var self = this,
  534. downBox = $('.layout-down'),
  535. ishave = downBox.length<=0 ? true : false;
  536. if(ishave) return false;
  537. var downEffect = function (opts) {
  538. var box = opts.el,
  539. txtBox = box.find('.downTxt'),
  540. down = box.find('ul'),
  541. list = down.find('li'),
  542. showAni = down.attr('data-effect')||'fadeInDown',
  543. hideAni = down.attr('data-hideAni')||'fadeOutDown';
  544. var ani = box.attr('data-ani') == 'true' ? true : false;
  545. var isOpen = function(){
  546. console.log("下拉");
  547. },//下拉时回调函数
  548. isClose = function(){
  549. console.log("未下拉");
  550. };//未下拉时回调函数
  551. function downToggle(e){
  552. var isActive = box.attr('data-on') == 'true' ? true : false;
  553. if( isActive ) {
  554. list.removeClass(showAni).addClass(hideAni);
  555. self.onEndAnimation(list[0],function(){
  556. down.hide();
  557. box.attr('data-ani','false');
  558. });
  559. // callback on close
  560. isClose( e );
  561. }
  562. else {
  563. down.show();
  564. list.removeClass(hideAni).addClass(showAni);
  565. // callback on open
  566. isOpen( e );
  567. box.attr('data-ani','false');
  568. }
  569. isActive = !isActive;
  570. box.attr('data-on',isActive);
  571. }
  572. box.on('click',function () {
  573. if(ani) return false;
  574. downToggle(down);
  575. });
  576. list.on('click',function(){
  577. var txt = $(this).html();
  578. txtBox.html(txt);
  579. });
  580. };
  581. downBox.each(function () {
  582. var _this = $(this);
  583. new downEffect({
  584. el : _this
  585. });
  586. });
  587. },
  588. //图片切割
  589. picCut:function () {
  590. var self = this,
  591. Tbox = $( '.picCut' ),
  592. ishave = Tbox.length<=0 ? true : false;
  593. if(ishave) return false;
  594. var Tpic = Tbox.find( 'img' ),
  595. src = Tpic.attr('src'),
  596. rang = Tbox.attr('data-hei'),
  597. boxMsg = {'width':Tbox.width(),'height':parseInt(Tbox.width()*rang)},
  598. rowNum = Tbox.attr( 'data-row' ),
  599. effect = Tbox.attr( 'data-effect' )||'',
  600. delay = Tbox.attr( 'data-delay' )||0,
  601. colNum = Tbox.attr( 'data-col' );
  602. var mwid = boxMsg.width/colNum,
  603. mhei = boxMsg.height/rowNum;
  604. var cut = null,
  605. Time = 0.0;
  606. cutItem= Tbox.find('.cutItem');
  607. cutItem.show();
  608. for(var i = 0;i<rowNum;i++){
  609. Time +=parseFloat(delay);
  610. for(var n = 0;n<colNum;n++){
  611. Time +=parseFloat(delay);
  612. str = '<div class="cut animated '+effect+'" style="animation-delay:'+Time+'s;width: '+mwid+'px;height:'+mhei+'px;top:'+mhei*i+'px;left:'+mwid*n+'px;"><img style="width: '+boxMsg.width+'px;height:'+boxMsg.height+'px;top:-'+mhei*i+'px;left:-'+mwid*n+'px;" src="'+src+'"></div>';
  613. Tbox.find('.cutItem').append(str);
  614. }
  615. }
  616. Time = (Time+0.6)*1000;
  617. setTimeout(function(){
  618. Tpic.show();
  619. cutItem.hide();
  620. },Time);
  621. },
  622. //单张图片切换动画(.Tpage,.moveNext,.movePrev);
  623. picMove:function(){
  624. var self = this,
  625. picBox = $('.component'),
  626. ishave = picBox.length<=0 ? true : false;
  627. if(ishave) return false;
  628. var moveEffect = function (opts) {
  629. var animEndEventNames = {
  630. 'WebkitAnimation' : 'webkitAnimationEnd',
  631. 'OAnimation' : 'oAnimationEnd',
  632. 'msAnimation' : 'MSAnimationEnd',
  633. 'animation' : 'animationend'
  634. },
  635. // animation end event name
  636. animEndEventName = animEndEventNames[ Modernizr.prefixed( 'animation' ) ],
  637. component = opts.parent || console.warn("no parent"),
  638. navNext = component.querySelector( '.moveNext' ),
  639. navPrev = component.querySelector( '.movePrev' ),
  640. pageChange = component.querySelector( '.pageChange' ),//可选择页数
  641. timer = null,
  642. loop = opts.loop == 'true' ? true :false,
  643. loopTime = opts.loopTime || 6000;//轮播间隔时间
  644. function reinit(_this,dir) {
  645. var items = component.querySelector( 'ul.itemwrap' ).querySelectorAll('li'),//图片项
  646. itemsCount = items.length,
  647. Tpage = $(component.querySelector( '.Tpage' )),
  648. current = parseInt(Tpage.attr( 'data-num' )),
  649. TpageChange = component.querySelectorAll( '[data-change]' ),
  650. ani = component.getAttribute('data-ani') == 'true' ? true : false,
  651. itemTxt = component.querySelectorAll( '[data-txt]');
  652. clearTimeout(timer);
  653. if(dir === 'num'){
  654. var Tnum = _this.attr('data-change');
  655. }
  656. navigate( dir , Tnum , ani , component,items,itemsCount,Tpage,current,TpageChange,itemTxt);
  657. }
  658. function goloop() {
  659. if(loop){
  660. timer=setTimeout(function () {
  661. reinit($(component),'next');
  662. },loopTime);
  663. }
  664. }
  665. function navigate( dir , num , Tani, component, items, itemsCount, Tpage, current, TpageChange, itemTxt) {
  666. if( Tani ) return false;
  667. component.setAttribute('data-ani','true');
  668. clearInterval(loop);
  669. var cntAnims = 0;
  670. var currentItem = items[ current ];
  671. var currentTxt = $(itemTxt).eq(current);
  672. if( dir === 'next' ) {
  673. current = current < itemsCount - 1 ? current + 1 : 0;
  674. }
  675. else if( dir === 'prev' ) {
  676. current = current > 0 ? current - 1 : itemsCount - 1;
  677. }
  678. else if( dir === 'num'){
  679. current = parseInt(num);
  680. }
  681. Tpage.html('0'+(current+1)).attr('data-num',current);
  682. $(TpageChange).eq(current).addClass('on').siblings().removeClass('on');
  683. var nextItem = items[ current ];
  684. var nextTxt = $(itemTxt).eq(current);
  685. var onEndAnimationCurrentItem = function() {
  686. this.removeEventListener( animEndEventName, onEndAnimationCurrentItem );
  687. classie.removeClass( this, 'current' );
  688. currentTxt.removeClass('on txtHide');
  689. classie.removeClass( this, dir === 'prev' ? 'navOutPrev' : 'navOutNext' );
  690. ++cntAnims;
  691. if( cntAnims === 2 ) {
  692. component.setAttribute('data-ani','false');
  693. goloop();
  694. }
  695. };
  696. var onEndAnimationNextItem = function() {
  697. this.removeEventListener( animEndEventName, onEndAnimationNextItem );
  698. classie.addClass( this, 'current' );
  699. nextTxt.addClass('on').removeClass('txtShow');
  700. classie.removeClass( this, dir === 'prev' ? 'navInPrev' : 'navInNext' );
  701. ++cntAnims;
  702. if( cntAnims === 2 ) {
  703. component.setAttribute('data-ani','false');
  704. goloop();
  705. }
  706. };
  707. if( self.support.animations ) {
  708. currentItem.addEventListener( animEndEventName, onEndAnimationCurrentItem );
  709. nextItem.addEventListener( animEndEventName, onEndAnimationNextItem );
  710. classie.addClass( currentItem, dir === 'prev' ? 'navOutPrev' : 'navOutNext' );
  711. classie.addClass( nextItem, dir === 'prev' ? 'navInPrev' : 'navInNext' );
  712. currentTxt.addClass('txtHide');
  713. nextTxt.addClass('txtShow');
  714. }
  715. else {
  716. console.log('不支持css3 animated');
  717. $(currentItem).hide();
  718. $(nextItem).fadeIn(200);
  719. setTimeout(function(){
  720. classie.removeClass( currentItem, 'current' );
  721. classie.addClass( nextItem, 'current' );
  722. component.setAttribute('data-ani','false');
  723. },200)
  724. }
  725. }
  726. navNext.addEventListener( 'click', function( ev ) {
  727. reinit($(this),'next');
  728. ev.preventDefault();
  729. } );
  730. navPrev.addEventListener( 'click', function( ev ) {
  731. reinit($(this),'prev');
  732. ev.preventDefault();
  733. } );
  734. var list = pageChange.querySelectorAll( '[data-change]' );
  735. for(var h=0;h<list.length;h++){
  736. list[h].addEventListener( 'click', function( ev ) {
  737. var Tcurrent =parseInt($(component).find('.Tpage').attr('data-num'));
  738. if(this.getAttribute('data-change')!=Tcurrent){
  739. reinit($(this),'num');
  740. }
  741. ev.preventDefault();
  742. } );
  743. }
  744. goloop();
  745. };
  746. picBox.each(function () {
  747. var el = $(this)[0];
  748. new moveEffect({
  749. parent: el,
  750. loop:el.getAttribute('data-loop'),
  751. loopTime:el.getAttribute('data-loopTime')
  752. });
  753. });
  754. },
  755. //单张图片切换动画(基于ThreeJS,不支持ie)
  756. webGl_picMove:function () {
  757. var self = this,
  758. picBox = $('.webGL-slider'),
  759. ishave = picBox.length<=0 ? true : false;
  760. if(ishave) return false;
  761. var webGlEffect = function(opts) {
  762. var pix={};
  763. var timer = null;
  764. var right= {
  765. vertex: '\n varying vec2 vUv;\n void main() {vUv = uv;gl_Position = projectionMatrix * modelViewMatrix * vec4( position, 1.0 );}',
  766. fragment : '\nvarying vec2 vUv;\nuniform sampler2D texture;uniform sampler2D texture2;uniform sampler2D disp;uniform float dispFactor;uniform float effectFactor;void main() {vec2 uv = vUv;vec4 disp = texture2D(disp, uv);vec2 distortedPosition = vec2(uv.x + dispFactor * (disp.r*effectFactor), uv.y);vec2 distortedPosition2 = vec2(uv.x - (1.0 - dispFactor) * (disp.r*effectFactor), uv.y);vec4 _texture = texture2D(texture, distortedPosition);vec4 _texture2 = texture2D(texture2, distortedPosition2);vec4 finalTexture = mix(_texture, _texture2, dispFactor);gl_FragColor = finalTexture;}'
  767. };
  768. var left= {
  769. vertex: '\n varying vec2 vUv;\n void main() {vUv = uv;gl_Position = projectionMatrix * modelViewMatrix * vec4( position, 1.0 );}',
  770. fragment : '\nvarying vec2 vUv;\nuniform sampler2D texture;uniform sampler2D texture2;uniform sampler2D disp;uniform float dispFactor;uniform float effectFactor;void main() {vec2 uv = vUv;vec4 disp = texture2D(disp, uv);vec2 distortedPosition = vec2(uv.x - dispFactor * (disp.r*effectFactor), uv.y);vec2 distortedPosition2 = vec2(uv.x + (1.0 - dispFactor) * (disp.r*effectFactor), uv.y);vec4 _texture = texture2D(texture, distortedPosition);vec4 _texture2 = texture2D(texture2, distortedPosition2);vec4 finalTexture = mix(_texture, _texture2, dispFactor);gl_FragColor = finalTexture;}'
  771. };
  772. var up= {
  773. vertex: '\n varying vec2 vUv;\n void main() {vUv = uv;gl_Position = projectionMatrix * modelViewMatrix * vec4( position, 1.0 );}',
  774. fragment : '\nvarying vec2 vUv;\nuniform sampler2D texture;uniform sampler2D texture2;uniform sampler2D disp;uniform float dispFactor;uniform float effectFactor;void main() {vec2 uv = vUv;vec4 disp = texture2D(disp, uv);vec2 distortedPosition = vec2(uv.x, uv.y + dispFactor * (disp.r*effectFactor));vec2 distortedPosition2 = vec2(uv.x, uv.y - (1.0 - dispFactor) * (disp.r*effectFactor));vec4 _texture = texture2D(texture, distortedPosition);vec4 _texture2 = texture2D(texture2, distortedPosition2);vec4 finalTexture = mix(_texture, _texture2, dispFactor);gl_FragColor = finalTexture;}'
  775. };
  776. var down= {
  777. vertex: '\n varying vec2 vUv;\n void main() {vUv = uv;gl_Position = projectionMatrix * modelViewMatrix * vec4( position, 1.0 );}',
  778. fragment : '\nvarying vec2 vUv;\nuniform sampler2D texture;uniform sampler2D texture2;uniform sampler2D disp;uniform float dispFactor;uniform float effectFactor;void main() {vec2 uv = vUv;vec4 disp = texture2D(disp, uv);vec2 distortedPosition = vec2(uv.x, uv.y - dispFactor * (disp.r*effectFactor));vec2 distortedPosition2 = vec2(uv.x, uv.y + (1.0 - dispFactor) * (disp.r*effectFactor));vec4 _texture = texture2D(texture, distortedPosition);vec4 _texture2 = texture2D(texture2, distortedPosition2);vec4 finalTexture = mix(_texture, _texture2, dispFactor);gl_FragColor = finalTexture;}'
  779. };
  780. var parent = opts.parent || console.warn("no parent");
  781. var dispImage = opts.displacementImage || 'dist/img/displacement/1.jpg';
  782. var images = opts.images,
  783. image = void 0,
  784. sliderImages = [];
  785. var prev = $(parent).find('.move-prev');
  786. var next = $(parent).find('.move-next');
  787. var intensity = opts.intensity || 1;
  788. var direction = opts.direction || 'right';
  789. var loop = opts.loop == 'true' ? true :false;
  790. var loopTime = opts.loopTime || 6000;
  791. switch(direction)
  792. {
  793. case 'right':
  794. pix = right;
  795. break;
  796. case 'left':
  797. pix = left;
  798. break;
  799. case 'up':
  800. pix = up;
  801. break;
  802. case 'down':
  803. pix = down;
  804. break;
  805. }
  806. var easing = opts.easing || Expo.easeOut;
  807. var canvasWidth = images[0].clientWidth;
  808. var canvasHeight = images[0].clientHeight;
  809. var renderWidth = parent.offsetWidth;
  810. var renderHeight = parent.offsetHeight;
  811. var renderW = void 0,
  812. renderH = void 0;
  813. if (renderWidth > canvasWidth) {
  814. renderW = renderWidth;
  815. } else {
  816. renderW = canvasWidth;
  817. }
  818. renderH = canvasHeight;
  819. var renderer = new THREE.WebGLRenderer({
  820. antialias: false
  821. });
  822. renderer.setPixelRatio(window.devicePixelRatio);
  823. renderer.setClearColor(0x23272A, 1.0);
  824. renderer.setSize(renderW, renderH);
  825. parent.appendChild(renderer.domElement);
  826. if (renderHeight > canvasHeight) {
  827. $(renderer.domElement).css('transform','scale('+(renderHeight/canvasHeight)+')');
  828. }
  829. var loader = new THREE.TextureLoader();
  830. loader.crossOrigin = "";
  831. images.forEach(function (img) {
  832. image = loader.load(img.getAttribute('src'));
  833. image.magFilter = image.minFilter = THREE.LinearFilter;
  834. image.anisotropy = renderer.capabilities.getMaxAnisotropy();
  835. sliderImages.push(image);
  836. });
  837. var length = sliderImages.length;
  838. var disp = loader.load(dispImage);
  839. disp.wrapS = disp.wrapT = THREE.RepeatWrapping;
  840. var scene = new THREE.Scene();
  841. scene.background = new THREE.Color(0x23272A);
  842. var camera = new THREE.OrthographicCamera(renderWidth / -2, renderWidth / 2, renderHeight / 2, renderHeight / -2, 1, 1000);
  843. camera.position.z = 1;
  844. var mat = new THREE.ShaderMaterial({
  845. uniforms: {
  846. effectFactor: { type: "f", value: intensity },
  847. dispFactor: { type: "f", value: 0.0 },
  848. texture: { type: "t", value: sliderImages[0] },
  849. texture2: { type: "t", value: sliderImages[1] },
  850. disp: { type: "t", value: disp }
  851. },
  852. vertexShader: pix.vertex,
  853. fragmentShader: pix.fragment,
  854. transparent: true,
  855. opacity: 1.0
  856. });
  857. var geometry = new THREE.PlaneBufferGeometry(parent.offsetWidth, parent.offsetHeight, 1);
  858. var object = new THREE.Mesh(geometry, mat);
  859. object.position.set(0, 0, 0);
  860. scene.add(object);
  861. var addEvents = function addEvents() {
  862. var pagButtons = Array.from(parent.querySelector('.pagination').querySelectorAll('a'));
  863. pagButtons.forEach(function (el) {
  864. el.addEventListener('click', function () {
  865. var ani = parent.getAttribute('data-ani') == 'false' ? false : true;
  866. if (!ani) {
  867. parent.setAttribute('data-ani','true');
  868. $(parent.querySelector('.pagination').querySelectorAll('[data-slide]')).removeClass('on');
  869. $(this).prevAll('a').addClass('lat2');
  870. $(this).addClass('on').removeClass('lat2');
  871. $(this).nextAll('a').removeClass('lat2');
  872. $(this).nextAll('a').removeClass('on');
  873. var slideId = parseInt(this.dataset.slide, 10);
  874. $(parent.querySelector('.txt-item').querySelectorAll('li')).fadeOut(300);
  875. $(parent.querySelector('.txt-item').querySelectorAll('li')).eq(slideId).fadeIn(1200);
  876. change(slideId);
  877. }
  878. });
  879. });
  880. };
  881. next.on('click',function () {
  882. var ani = parent.getAttribute('data-ani') == 'false' ? false : true;
  883. if (!ani) {
  884. parent.setAttribute('data-ani','true');
  885. $(parent.querySelector('.pagination').querySelectorAll('[data-slide]')).removeClass('on');
  886. var slideId = parseInt(parent.getAttribute('data-cur')) || 0;
  887. slideId = slideId < length-1 ? slideId + 1 : 0;
  888. $(parent.querySelector('.pagination').querySelectorAll('[data-slide]')).eq(slideId).prevAll('a').addClass('lat2');
  889. $(parent.querySelector('.pagination').querySelectorAll('[data-slide]')).eq(slideId).addClass('on').removeClass('lat2');
  890. $(parent.querySelector('.pagination').querySelectorAll('[data-slide]')).eq(slideId).nextAll('a').removeClass('lat2');
  891. $(parent.querySelector('.pagination').querySelectorAll('[data-slide]')).eq(slideId).nextAll('a').removeClass('on');
  892. $(parent.querySelector('.pagination').querySelectorAll('[data-slide]')).eq(slideId).addClass('on');
  893. $(parent.querySelector('.txt-item').querySelectorAll('li')).fadeOut(300);
  894. $(parent.querySelector('.txt-item').querySelectorAll('li')).eq(slideId).fadeIn(800);
  895. change(slideId);
  896. }
  897. });
  898. prev.on('click',function () {
  899. var ani = parent.getAttribute('data-ani') == 'false' ? false : true;
  900. if (!ani) {
  901. parent.setAttribute('data-ani','true');
  902. $(parent.querySelector('.pagination').querySelectorAll('[data-slide]')).removeClass('on');
  903. var slideId = parseInt(parent.getAttribute('data-cur')) || 0;
  904. slideId = slideId > 0 ? slideId - 1 : length-1;
  905. $(parent.querySelector('.pagination').querySelectorAll('[data-slide]')).eq(slideId).prevAll('a').addClass('lat2');
  906. $(parent.querySelector('.pagination').querySelectorAll('[data-slide]')).eq(slideId).addClass('on').removeClass('lat2');
  907. $(parent.querySelector('.pagination').querySelectorAll('[data-slide]')).eq(slideId).nextAll('a').removeClass('lat2');
  908. $(parent.querySelector('.pagination').querySelectorAll('[data-slide]')).eq(slideId).nextAll('a').removeClass('on');
  909. $(parent.querySelector('.pagination').querySelectorAll('[data-slide]')).eq(slideId).addClass('on');
  910. $(parent.querySelector('.txt-item').querySelectorAll('li')).fadeOut(300);
  911. $(parent.querySelector('.txt-item').querySelectorAll('li')).eq(slideId).fadeIn(800);
  912. change(slideId);
  913. }
  914. });
  915. function change(num) {
  916. clearTimeout(timer);
  917. mat.uniforms.texture2.value = sliderImages[num];
  918. mat.uniforms.texture2.needsUpdate = true;
  919. TweenLite.to(mat.uniforms.dispFactor, 1, {
  920. value: 1,
  921. ease: easing,
  922. onComplete: function onComplete() {
  923. mat.uniforms.texture.value = sliderImages[num];
  924. mat.uniforms.texture.needsUpdate = true;
  925. mat.uniforms.dispFactor.value = 0.0;
  926. self.isAnimating2 = false;
  927. parent.setAttribute('data-cur',num);
  928. parent.setAttribute('data-ani','false');
  929. myloop();
  930. }
  931. });
  932. }
  933. addEvents();
  934. setTimeout(function () {
  935. $(parent.querySelector('.pagination').querySelectorAll('[data-slide]')).eq(0).addClass('on');
  936. },100)
  937. function myloop(){
  938. if(loop){
  939. timer = setTimeout(function () {
  940. var ani = parent.getAttribute('data-ani') == 'false' ? false : true;
  941. if (!ani) {
  942. parent.setAttribute('data-ani','true');
  943. var slideId = parseInt(parent.getAttribute('data-cur')) || 0;
  944. slideId = slideId < length-1 ? slideId + 1 : 0;
  945. change(slideId);
  946. if(slideId==0){
  947. $(parent.querySelector('.pagination').querySelectorAll('[data-slide]')).removeClass('on');
  948. $(parent.querySelector('.pagination').querySelectorAll('[data-slide]')).removeClass('lat2');
  949. }
  950. setTimeout(function () {
  951. $(parent.querySelector('.pagination').querySelectorAll('[data-slide]')).eq(slideId).addClass('on');
  952. },20);
  953. $(parent.querySelector('.txt-item').querySelectorAll('li')).fadeOut(300);
  954. $(parent.querySelector('.txt-item').querySelectorAll('li')).eq(slideId).fadeIn(1200);
  955. }
  956. },loopTime);
  957. }
  958. }
  959. window.addEventListener('resize', function (e) {
  960. renderer.setSize(renderW, renderH);
  961. });
  962. var animate = function animate() {
  963. requestAnimationFrame(animate);
  964. renderer.render(scene, camera);
  965. };
  966. animate();
  967. myloop();
  968. };
  969. picBox.each(function () {
  970. var el = $(this)[0];
  971. var imgs = Array.from(el.querySelectorAll('.img-list'));
  972. new webGlEffect({
  973. parent: el,
  974. intensity: el.getAttribute('data-intensity') || undefined,
  975. easing: el.getAttribute('data-easing') || undefined,
  976. images: imgs,
  977. direction:el.getAttribute('data-direction'),
  978. displacementImage: el.getAttribute('data-displacement'),
  979. loop:el.getAttribute('data-loop'),
  980. loopTime:el.getAttribute('data-loopTime')
  981. });
  982. });
  983. },
  984. //弹窗
  985. dialog:function(){
  986. var self = this,
  987. have = $('[data-dialog]'),
  988. ishave = have.length<=0 ? true : false;
  989. if(ishave) return false;
  990. var dialogEffect = function (opts) {
  991. var parent = opts.el;
  992. var dialog = opts.dialog,
  993. closeBtn = dialog.find('[data-dialog-close]'),
  994. mask = dialog.find( '.dialog_mask' ),
  995. video = dialog.find('video'),
  996. morphEl = dialog.find('.morph-shape');
  997. if(morphEl.length>0){
  998. var path = morphEl[0].querySelector('path'),
  999. steps = {
  1000. open : morphEl[0].getAttribute( 'data-morph-open' ),
  1001. close : morphEl[0].getAttribute( 'data-morph-close' )
  1002. };
  1003. }
  1004. var onOpenDialog = function(){
  1005. console.log("弹窗打开");
  1006. var url = parent.attr('data-src');
  1007. if(morphEl.length>0){
  1008. anime({
  1009. targets: path,
  1010. duration: 400,
  1011. easing: 'linear',
  1012. d: steps.open,
  1013. complete: function() {}
  1014. });
  1015. }
  1016. if(video.length>0){
  1017. video.attr('src',url);
  1018. video[0].currentTime=5;
  1019. video[0].play();
  1020. }
  1021. };//弹窗打开时回调函数
  1022. var onCloseDialog = function(){
  1023. console.log("弹窗关闭");
  1024. if(morphEl.length>0){
  1025. anime({
  1026. targets: path,
  1027. duration: 400,
  1028. easing: 'linear',
  1029. d: steps.close,
  1030. complete: function() {}
  1031. });
  1032. }
  1033. if(video.length>0){
  1034. video[0].pause();
  1035. }
  1036. };//弹窗关闭时回调函数
  1037. function dialogToggle(e,isOpen){
  1038. if( isOpen ) {
  1039. classie.remove( e, 'dialog--open' );
  1040. classie.add( e, 'dialog--close' );
  1041. self.onEndAnimation(e.querySelector( '.dialog_content' ),function(){
  1042. classie.remove( e, 'dialog--close' );
  1043. onCloseDialog( );
  1044. });
  1045. }
  1046. else {
  1047. classie.add( e, 'dialog--open' );
  1048. // callback on open
  1049. onOpenDialog( this );
  1050. }
  1051. isOpen = !isOpen;
  1052. e.setAttribute('data-isOpen',isOpen);
  1053. }
  1054. parent.on("click",function () {
  1055. var isOpen = dialog.attr('data-isOpen') == 'true' ? true : false;
  1056. var isclick = dialog.attr('data-isclick');
  1057. dialogToggle(dialog[0],isOpen);
  1058. if(isclick == undefined){
  1059. closeBtn.on('click',function () {
  1060. dialogToggle(dialog[0],true);
  1061. });
  1062. mask.on('click',function () {
  1063. dialogToggle(dialog[0],true);
  1064. });
  1065. dialog.attr('data-isclick','true');
  1066. }
  1067. });
  1068. };
  1069. have.each(function () {
  1070. var _this = $(this),
  1071. _dialog = $('#'+_this.attr('data-dialog'));
  1072. new dialogEffect({
  1073. el:_this,
  1074. dialog : _dialog
  1075. });
  1076. });
  1077. },
  1078. //tab选项
  1079. tabBox:function () {
  1080. var self = this,
  1081. Tbox = $( '.layout-tabBox' ),
  1082. ishave = Tbox.length<=0 ? true : false;
  1083. if(ishave) return false;
  1084. var partItem = Tbox.find('.layout-part'),
  1085. partName = null,
  1086. partChoose = partItem.find('li');
  1087. partChoose.on('click',function (e) {
  1088. partName = $(this).parents('.layout-part').attr('data-part');
  1089. var _this = $(this),
  1090. item = $('.'+partName),
  1091. list = _this.attr('data-list');
  1092. for(var i=0;i<item.length;i++){
  1093. var cur = $(item[i]);
  1094. cur.hide();
  1095. if(cur.hasClass(list)){
  1096. cur.show();
  1097. }
  1098. }
  1099. });
  1100. },
  1101. touchMove:function (el) {
  1102. var self = this;
  1103. var move = {};
  1104. el.on('touchstart',function(e){
  1105. //获取接触屏幕时的X和Y
  1106. move.endX = 0;
  1107. move.endY = 0;
  1108. move.startX = e.originalEvent.changedTouches[0].pageX;
  1109. move.startY = e.originalEvent.changedTouches[0].pageY;
  1110. });
  1111. el.on('touchmove',function(e) {
  1112. //获取滑动屏幕时的X,Y
  1113. move.endX = e.originalEvent.changedTouches[0].pageX;
  1114. move.endY = e.originalEvent.changedTouches[0].pageY;
  1115. });
  1116. el.on('touchend',function(e) {
  1117. //获取滑动屏幕时的X,Y
  1118. if(move.endX ==0 || move.endY ==0){
  1119. var distanceX = 0;
  1120. var distanceY = 0;
  1121. }else{
  1122. var distanceX = move.endX - move.startX;
  1123. var distanceY = move.endY - move.startY;
  1124. }
  1125. if (Math.abs(distanceX) > Math.abs(distanceY) && distanceX > 50) {
  1126. self.appDirection='left';
  1127. }
  1128. else if (Math.abs(distanceX) > Math.abs(distanceY) && distanceX < (-50)) {
  1129. self.appDirection='right';
  1130. }
  1131. else if (Math.abs(distanceX) < Math.abs(distanceY) && distanceY > 50) {
  1132. self.appDirection='up';
  1133. }
  1134. else if (Math.abs(distanceX) < Math.abs(distanceY) && distanceY < (-50)) {
  1135. self.appDirection='down';
  1136. }
  1137. });
  1138. },
  1139. //回到顶部
  1140. toTop:function () {
  1141. var self = this;
  1142. var top_btn = $('.toTop'),
  1143. isHave = top_btn.length <= 0 ? true : false;
  1144. if(isHave) return false;
  1145. top_btn.on('click',function () {
  1146. $("html,body").animate({scrollTop:0}, 600);
  1147. });
  1148. $(window).scroll(function(){
  1149. if($(this).scrollTop()>(self.windowWidth/4)){
  1150. top_btn.addClass('on');
  1151. }else{
  1152. top_btn.removeClass('on');
  1153. }
  1154. });
  1155. },
  1156. //视频播放
  1157. video_setting:function () {
  1158. var self = this,
  1159. Tplay = $('[data-play]'),
  1160. ishave = Tplay.length<=0 ? true : false;
  1161. if(ishave) return false;
  1162. var medio = null,
  1163. isplay = null;
  1164. Tplay.on('click',function () {
  1165. var _this = $(this);
  1166. medio = $('#'+$(this).attr('data-play'));
  1167. isplay = $(this).hasClass('on') ? true : false;
  1168. if(isplay){
  1169. medio[0].pause();
  1170. }else{
  1171. medio[0].play();
  1172. }
  1173. _this.toggleClass('on');
  1174. medio.one('click',function () {
  1175. isplay = _this.hasClass('on') ? true : false;
  1176. console.log(isplay);
  1177. if(isplay){
  1178. $(this)[0].pause();
  1179. }else{
  1180. $(this)[0].play();
  1181. }
  1182. _this.toggleClass('on');
  1183. });
  1184. });
  1185. },
  1186. //页面节点相互监听
  1187. nodeName:function () {
  1188. var self = this,
  1189. node = $('.nodeItem'),
  1190. ishave = node.length<=0 ? true : false;
  1191. if(ishave) return false;
  1192. var name = $('.rowName');
  1193. for(var n=0;n<name.length;n++){
  1194. var row = {};
  1195. var _this = name[n];
  1196. row.id = $(_this).parents('.row').attr('id');
  1197. row.top = $(_this).offset().top - (data.win_h/2);
  1198. self.rowNode.push(row);
  1199. }
  1200. nodeChange();
  1201. function nodeChange(){
  1202. var top = $(document).scrollTop();
  1203. if(top>400){
  1204. node.addClass('on');
  1205. }else{
  1206. node.removeClass('on');
  1207. }
  1208. for(var i=self.rowNode.length-1;i>=0;i--){
  1209. var _this = self.rowNode[i];
  1210. if(top>=_this.top){
  1211. $('.nodeItem > a').eq(i).addClass('on').siblings().removeClass('on');
  1212. break;
  1213. }
  1214. }
  1215. }
  1216. $(window).scroll(function () {
  1217. nodeChange();
  1218. });
  1219. }
  1220. };
  1221. $.fn.myFn = function() {
  1222. new Tfn().init();
  1223. };
  1224. })(jQuery, window, document);
  1225. $(document).myFn();
  1226. //input[type=range]
  1227. $.fn.RangeSlider = function(cfg){
  1228. this.sliderCfg = {
  1229. min: cfg && !isNaN(parseFloat(cfg.min)) ? Number(cfg.min) : null,
  1230. max: cfg && !isNaN(parseFloat(cfg.max)) ? Number(cfg.max) : null,
  1231. step: cfg && Number(cfg.step) ? cfg.step : 1,
  1232. callback: cfg && cfg.callback ? cfg.callback : null
  1233. };
  1234. var $input = $(this);
  1235. var min = this.sliderCfg.min;
  1236. var max = this.sliderCfg.max;
  1237. var step = this.sliderCfg.step;
  1238. var callback = this.sliderCfg.callback;
  1239. $input.attr('min', min)
  1240. .attr('max', max)
  1241. .attr('step', step);
  1242. $input.bind("input", function(e){
  1243. $input.attr('value', this.value);
  1244. $input.css( 'background-size', this.value + '% 100%' );
  1245. if ($.isFunction(callback)) {
  1246. callback(this);
  1247. }
  1248. });
  1249. };