// "use strict"; // !+[1,] ? alert('ie') : alert('other'); // alert(window.navigator.userAgent); // e.stopPropagation(); _setting = { toggleImageSize: false, toggleLazyload: false, imgUrl : 'images/' } $(window).scroll(function() { scrollx = $(document).scrollTop(); //basic.lazyload(); }); $(window).resize(function() { basic.lockscale(); }); $(document).ready(function() { basic.lockscale(); basic.animated(); basic.table(); // _setting.toggleLazyload ? basic.lazyload() : null; // _setting.toggleImageSize ? basic.imglength : null; // basic.grids(); // basic.deviceRotate(); // nicescroll(); // mousewheel(); if(typeof(navdata)!="undefined") {gobal.navs(navdata);} gobal.fontlength; if(version()!='Chrome'&&version()!='FireFox'&&version()!='FireFox'&&version()!='Opera'&&!mobile()) { $('.notice').slideDown(); } if(mobile()&&$(window).width()>480) { _oft = $('.warpper').offset().top; $("html,body").animate({scrollTop:_oft-$('.header').outerHeight()},500); } $(window).scroll(function() { _offsetTop = $(window).scrollTop(); if(_offsetTop>=100) { $('.header').addClass('lock'); }else{ $('.header').removeClass('lock'); } }); $('.menuToggler').click(function() { if($('.header .list').is(':visible')) { $(this).removeClass('active'); $('.header .list').hide(); }else{ $(this).addClass('active'); $('.header .list').show(); } }); $('.cyly .digest .r p').click(function() { if($(window).width() <= 480 ) { $(this).toggleClass('active'); } }); if($(window).width()<=480&&$('.news .showcase .con').length>=2) { $('.news .showcase').bxSlider({ pager: false, auto: true, pause: 5e3, controls: false }); } }); var about = { milestone: function(url,n) { n = typeof(n) == 'undefined' ? 0 : n; $.get(url, function(xml) { data = $(xml).toObject().get(0).history._tab; // console.dir(data); $.each(data,function(k, year) { _class = k==0 ? ' class="active" ' : ''; _prev = k==0 ? '' : ''; _next = k==data.length-1 ? '' : ''; _tool = '
'+_prev+_next+'
'; $('.milestone:eq('+n+') .years ul').append('
  • '+year._name+'
  • '); $('.milestone:eq('+n+') .things').append('
    '+year._name+_tool+'
    '); // 年份下如果是单条事件就直接一个对象, 反之则是事件数组. if(typeof(year.son)!='undefined') { if(typeof(year.son.about)!='undefined') { _text = year.son.about.replace(/[  \t]/g,'').replace(/^/g,''); // 替换掉空格, 双刃剑吧, 可能以后会用到空格, 但目前的空格会导致排版不对齐难看, 以后可能会恢复. $('.milestone:eq('+n+') .things dl[year='+year._name+']').append('
    '+1+''+_text+'
    '); }else{ $.each(year.son, function(i, item) { _text = item.about.replace(/[  \t]/g,'').replace(/^/g,''); $('.milestone:eq('+n+') .things dl[year='+year._name+']').append('
    '+(i+1)+''+_text+'
    '); }); } } }); about.initStyle(); // 初始化结束 $('.milestone:eq('+n+')').on('click','.years ul li a, .things dt a',function() { _delayTime = 0.1; if($('.milestone:eq('+n+')').hasClass('acting')) { return false; } $('.milestone:eq('+n+')').addClass('acting'); _year = $(this).attr('year'); $('.years ul li a[year='+_year+']').parent('li').addClass('active').siblings('li').removeClass('active'); _current = $('.milestone:eq('+n+') .things dl.active'); _target = $('.milestone:eq('+n+') .things dl[year='+_year+']'); _size = _current.find('dd').length + 1; _current.find('dt').removeClass('animated fadeInDown').addClass('animated fadeOutUp'); _current.find('dd').removeClass('animated fadeInUp').addClass('animated fadeOutUp'); setTimeout(function() { _current.removeClass().removeAttr('style'); _target.find('dt').addClass('animated fadeInDown'); _current.find('dt, dd').removeClass().removeAttr('style'); _target.find('dd').each(function(i) { _delay = (i+1) * _delayTime + _delayTime; $(this).css({ 'animation-delay': _delay + 's', '-webkit-animation-delay': _delay + 's', '-o-animation-delay': _delay + 's', '-moz-animation-delay': _delay + 's' }); $(this).addClass('animated fadeInUp'); }); _target.addClass('active'); $('.milestone:eq('+n+')').removeClass('acting'); }, _size * _delayTime * 1e3); }); $('.milestone:eq('+n+')').on('click','.timeline>.btn',function() { _max = $('.milestone:eq('+n+') .timeline .years ul').outerWidth() - $('.milestone:eq('+n+') .timeline .years').width(); _page = $('.milestone:eq('+n+') .timeline .years').width(); _offset = $('.milestone:eq('+n+')').attr('offset') ? parseFloat($('.milestone:eq('+n+')').attr('offset')) : 0; if($(this).hasClass('lineprev')) { if(_offset == 0) { return false; } _offset = _offset - _page >= 0 ? _offset - _page : 0; }else{ if(_offset == _max) { return false; } _offset = _offset + _page <= _max ? _offset + _page : _max; } $('.milestone:eq('+n+')').attr('offset',_offset); $('.milestone:eq('+n+') .years ul').css({ marginLeft: (0 - _offset) + 'px' }); }); }); }, initStyle: function() { _minWidth = $(window).width() > 480 ? 150 : 80; //_minWidth = 150; //设置最低宽度; $('.milestone').each(function(k) { _containerWidth = $(this).find('.timeline').width(); _amountPerline = Math.floor(_containerWidth/_minWidth); _amounts = $(this).find('.timeline .years li').length; _itemWidth = _containerWidth/_amountPerline; $(this).find('.timeline .years li').css({width: _itemWidth+'px'}); $(this).find('.timeline .years ul').css({width: _itemWidth * _amounts+'px'}); if($(this).attr('offset')) { _offset = $(this).attr('offset'); _m = Math.floor(_offset/_minWidth); $(this).find('.years ul').css({marginLeft: 0 - _m * _itemWidth + 'px'}); $(this).attr('offset', _m * _itemWidth) } }); } } var gobal = { fontsize: function() { if($cookie.get('fontsize')) { _size = $cookie.get('fontsize'); $('.nd .tools a.'+_size).addClass('active'); switch (_size) { case 'small': $('.nd .detial').css({zoom: 0.75}) ;break; case 'medium': $('.nd .detial').css({zoom: 1}) ;break; case 'large': $('.nd .detial').css({zoom: 1.25}) ;break; default: $('.nd .detial').css({zoom: 1}) ;break; } }else{ $cookie.set('fontsize','medium',30); } $('.nd .tools a').click(function() { if($(this).hasClass('font')) { $(this).addClass('active').siblings('.font').removeClass('active'); _size = $(this).attr('class').replace('font','').replace('active','').replace(/[ ]/g,''); $cookie.set('fontsize',_size,30); switch (_size) { case 'small': $('.nd .detial').css({zoom: 0.75}) ;break; case 'medium': $('.nd .detial').css({zoom: 1}) ;break; case 'large': $('.nd .detial').css({zoom: 1.25}) ;break; default: $('.nd .detial').css({zoom: 1}) ;break; } } }); }, navs : function(navdata) { if(typeof(navdata)!="undefined") { _html = ''; $.each(navdata,function(k,v) { _href = window.location.href; _active = _href.indexOf(v.url)>=0 ? 'class="active"' : ''; if(v.url.indexOf('#url')>=0) { _url = v.url.split('|')[1]; _html += ''+v.name+''; }else{ if(v.url.indexOf('#goto')>=0) { _goto = v.url.split('|')[1]; _active = k==0 ? 'class="active"' : ''; _html += ''+v.name+''; }else{ _html += ''+v.name+''; } } }); $('.navs').addClass('animateall clear').html('
    '+_html+'
    '); }else{ console.warn('undefined navs, it will be blank'); } if($('.navs a').length>0) { _total = 0; _m = $('.navs a').length; } } } function hint($msg,$time,$type) { $time = $time*1e3; $('.hintmsg.temp').remove(); $('body').append('
    '+$msg+'
    ') setTimeout(function() { $('.hintmsg').addClass('fadeOutUp animated temp'); },$time); } $.fn.ratio = function($option) { var $setting = { scale : 3/4, overflow: false } $.extend($setting,$option); var $obj = this; $width = parseInt($obj.width()); $height = $width * $setting.scale; if($setting.overflow) { $overflow = 'visible' }else{ $overflow = 'hidden' } $obj.css({ 'height': $height, 'overflow': $overflow }); } $.fn.forslide = function(_option) { _temp = ''; _html = ''; var _setting = { item : '.item', step : 4, tagName: 'li', tagClass: '', clear: false, attr: '', callback: function() {} } $.extend(_setting,_option); o = this; _size = o.find(_setting.item).length; if(_setting.clear){ _clear='
    '; }else{ _clear=''; } if(_size>_setting.step){ if(_size % _setting.step == 0){ for(_i=0;_i<_size;_i++){ _temp += o.find( _setting.item+':eq('+_i+')').prop('outerHTML'); if((_i+1)% _setting.step == 0) { _html += '<'+_setting.tagName+' '+_setting.attr+' class="'+_setting.tagClass+'">' + _temp + _clear + '' ; _temp = ''; } } }else{ _page = Math.floor(_size/_setting.step); for(_i=0; _i<_size; _i++ ){ _temp += o.find( _setting.item+':eq('+_i+')').prop('outerHTML'); if((_i+1)%_setting.step==0&&_i+1<=_page*_setting.step){ _html += '<'+_setting.tagName+' '+_setting.attr+' class="'+_setting.tagClass+'">' + _temp + _clear + '' ; _temp = ''; } } _html += '<'+_setting.tagName+' '+_setting.attr+' class="'+_setting.tagClass+'">' + _temp + _clear + '' ; } }else{ _html += '<'+_setting.tagName+' '+_setting.attr+' class="'+_setting.tagClass+'">' + o.html() + '' ; } o.empty().append(_html); _setting.callback(); } var basic = { lockscale: function() { $('[lockscale]').each(function() { scale = eval($(this).attr('lockscale')); $(this).css({ 'min-height': $(this).width() * scale }); }); }, table: function() { $('table').each(function() { if($(this).attr('responseTable')) { _attr = $(this).get(0).attributes; _class = $(this).attr('class'); _class ? null : _class = 'normal'; if($(this).find('tr').eq(0).find('th').length>1) { side = 'shu'; isTable = true; }else if($(this).find('tr').eq(0).find('th').length==1) { side = 'heng'; isTable = true; }else{ isTable = false; } if(isTable&&side=='shu') { _ths = []; $(this).find('tr').eq(0).find('th').each(function() { _ths.push($(this).html()); }); _trs = []; $(this).find('tr').each(function(i) { _tds = []; if(i!=0) { $(this).find('td').each(function() { _tds.push($(this).html()); }); _trs.push(_tds); } }); // 生成html $table = $('
    '); $tr = $('
    '); $.each(_ths,function(k,v) { $th = $('
    ').append($(''+v+'')); $tr.append($th); }); $table.append($tr); $.each(_trs,function(row,rowdata) { row++; $tr = $('
    '); $.each(rowdata,function(k,v) { $td = $('
    ').append($(''+_ths[k]+'')).append($(''+v+'')); $tr.append($td); }); $table.append($tr); }); $.each(_attr,function(k,v) { $table.attr(v.nodeName,v.value); }); $table.addClass('table hengTable'); $(this).replaceWith($table); }else if(isTable&&side=='heng') { _ths = []; _this = $(this); _trs = []; $(this).find('tr').each(function(i) { _trs[i] = []; _ths.push($(this).find('th').html()); $(this).find('td').each(function() { _trs[i].push($(this).html()); }); }); // console.dir(_trs); //生成html $table = $('
    '); $column = $('
    '); $.each(_ths,function(k,v) { columnNum = k+1; $column.append($('
    '+v+'
    ')); }); $table.append($column); $.each(_trs[0],function(k) { console.log(k); columnNum = k+1; $column = $('
    '); $.each(_trs,function(row,data) { $column.append($('
    '+_ths[row]+''+data[k]+'
    ')); }); $table.append($column); }); $.each(_attr,function(k,v) { $table.attr(v.nodeName,v.value); }); $table.addClass('table shuTable'); $(this).replaceWith($table); }else{ _ths = []; _this = $(this); _trs = []; $(this).find('tr').each(function(i) { _trs[i] = []; $(this).find('td').each(function() { _trs[i].push($(this).html()); }); }); $table = $('
    '); $.each(_trs[0],function(k) { console.log(k); columnNum = k+1; $column = $('
    '); $.each(_trs,function(row,data) { $column.append($('
    '+data[k]+'
    ')); }); $table.append($column); }); $.each(_attr,function(k,v) { $table.attr(v.nodeName,v.value); }); $table.addClass('table normalTable'); $(this).replaceWith($table); } } }); }, lazyload: function() { $('[lazyload]').each(function() { if(!$(this).attr('src')) { $(this).css({"background":"url("+_setting.imgUrl+"bx_loader.gif) no-repeat center center"}); } if($(this).offset().top - $(window).height() <= $(window).scrollTop() ) { if(!$(this).attr('src')) { $(this).attr("src",$(this).attr("lazyload")); if(_setting.toggleImageSize) { var img_url = $(this).attr('src'); obj = $(this); var img = new Image(); img.src = img_url; var check = function(){ if(img.width>0 || img.height>0) { obj.attr('data-width',img.width); obj.attr('data-height',img.height); clearInterval(set); } }; var set = setInterval(check,40); } } } $(this).load(function() { $(this).css({"background": "none"}); }); }); }, imgsize: function() { imgAmount = $('img[src]').length; renderid = 0; loadnext = function(obj) { var img_url = obj.attr('src'); var img = new Image(); img.src = img_url; var check = function(){ if(img.width>0 || img.height>0) { obj.attr('data-width',img.width); obj.attr('data-height',img.height); clearInterval(set); renderid++; renderid < imgAmount ? loadnext($('img').eq(renderid)): null; } }; var set = setInterval(check,40); } loadnext($('img').eq(renderid)); }, grids: function() { $css = []; $('.row').each(function() { mds = '.md1,.md2,.md3,.md4,.md5,.md6,.md7,.md8,.md9,.md10,.md11,.md12,.dv'; per = 100 / $(this).find('.dv').length; $(this).find('.dv').css({ width: per +'%'}); $(this).find(mds).each(function() { $html = $(this).html(); $margin = $(this).css('margin'); $(this).addClass('mp0'); $(this).html('
    '+$html+'
    '); if($margin!='0px') { $thisClass = '.' + $(this).attr('class').replace(/\s+/g,"."); $parent = $(this).parents('[class]'); $parentClass= []; if($parent.attr('class')) { $parentClass.push($parent.attr('class').replace(/\s+/g,".")); } for( i = 0 ; i < 5 ; i ++ ) { $parent = $parent.parents('[class]'); if($parent.attr('class')) { $parentClass.push($parent.attr('class').replace(/\s+/g,".")); } } $parentClasses = ''; for( i = $parentClass.length-1 ; i > 0 ; i-- ) { $parentClasses += '.' + $parentClass[i] + ' '; } $thisClassPath = $tcp = $parentClasses + $thisClass ; $thisCss = $thisClassPath + ' .item {margin: '+$margin+'}'; $css.push($thisCss); } }); }); $ncss = []; for(var i=0;i<$css.length;i++) {   var items=$css[i];   //判断元素是否存在于new_arr中,如果不存在则插入到new_arr的最后   if($.inArray(items,$ncss)==-1) { $ncss.push(items);   } } $css = ''; for( i = 0; i < $ncss.length ; i++ ) { $css += $ncss[i]; } $('').insertBefore('head'); }, deviceRotate: function() { if(mobile()) { window.addEventListener("onorientationchange" in window ? "orientationchange" : "resize", function() { if (window.orientation === 180 || window.orientation === 0) { $('body').addClass('vertical'); } if (window.orientation === 90 || window.orientation === -90 ){ $('body').addClass('horizontal'); } }, false); } }, animated: function() { $('[firstactive]').each(function() { $tar = $(this).attr('firstactive'); $(this).find($($tar)).eq(0).addClass('active'); }); $('[prefix]').each(function() { $prefix = $(this).attr('prefix'); if($(this).attr('child')) { $child = $(this).attr('child'); $(this).find($child).each(function(_i) { _i+=1; $(this).addClass($prefix).addClass($prefix+_i); }); }else{ $(this).each(function(_i) { _i+=1; $(this).addClass($prefix).addClass($prefix+_i); }); } }); $('[split]').each(function() { _temp = []; _html = ''; $tar = $(this).attr('split'); $text = $(this).text(); for(i=0;i<$text.length;i++) { _temp.push($text.substring(i,i+1)); } for(i=0;i<_temp.length;i++) { if(_temp[i]=="#") { _html += '
    '; }else { _html += '<'+$tar+'>'+_temp[i]+''; } } $(this).html(_html); }); $('[splitwith]').each(function() { _temp = []; _html = ''; $tar = $(this).attr('splitwith'); $text = $(this).text(); _temp = $text.split($tar); for(i=0;i<_temp.length;i++) { if(_temp[i]=="#") { _html += '
    '; }else { _html += ''+_temp[i]+' '; } } $(this).html(_html); }); $('body').on('click','[goto]',function() { $tar = $(this).attr('goto'); $("html,body").animate({scrollTop:$($tar).offset().top-$('.header').outerHeight()-10},1000); }); $('[vcenter]').each(function() { tar = $(this).attr('vcenter'); _html = $(this).find(tar).prop('outerHTML'); $(this).html('
    '); $(this).find('table').append(''+_html+''); }); $('[absovcenter]').each(function() { $target = $(this).attr('absovcenter'); $position = $(this).css('position'); if($position!='absolute'&&$position!='relative'&&$position!='fixed') { $(this).css({ position: 'relative' }); } $targetHeight = $(this).find($target).outerHeight(); $(this).find($target).css({ position: 'absolute', top: '50%', marginTop: -$targetHeight / 2 }); }); $('[imgvcenter]').each(function() { tar = $(this).attr('imgvcenter'); outheight =$(this).height(); $(this).find(tar).load(function() { inheight = $(this).outerHeight(); $(this).css({ 'margin-top': (outheight-inheight)/2 }); }); }); $('[eachdelay]').each(function() { delaytarget=$(this).attr('eachdelay'); delaytime=$(this).attr('delaytime')/1000; if(typeof($(this).attr('delaystart'))!='undefined') { delay = parseInt($(this).attr('delaystart')) / 1000; }else{ delay = 0; } $(this).find(delaytarget).each(function() { $(this).css({ 'animation-delay': delay + 's', '-webkit-animation-delay': delay + 's', '-o-animation-delay': delay + 's', '-moz-animation-delay': delay + 's' }); delay+=delaytime; }); }); $('[hover]').each(function() { $(this).mouseenter(function() { animate = $(this).attr('hover'); if($(this).attr("effect")){ effectchild = $(this).attr("effect"); $(this).find(effectchild).addClass(animate+" animated"); }else{ $(this).addClass(animate+" animated"); } }); $(this).mouseleave(function() { animate = $(this).attr('hover'); if($(this).attr("effect")){ effectchild = $(this).attr("effect"); $(this).find(effectchild).removeClass(animate+" animated"); }else{ $(this).removeClass(animate+" animated"); } }); }); $('[animate]').each(function() { animate = $(this).attr('animate'); if(animate.indexOf(',')>=0){ arr = animate.split(','); }else{ arr = ["fadeIn","zoomIn","fadeInUp","fadeInRight","fadeInDown","fadeInLeft"]; } if($(this).attr('effect')){ if($(this).attr('animateClass')) { if(animate=="random"||animate.indexOf(',')>=0) { $(this).find($(this).attr('effect')).each(function() { random = Math.floor(Math.random()*(arr.length)); random = arr[random]; $(this).addClass(random+' '+$(this).attr('animateClass')); }); }else{ $(this).find($(this).attr('effect')).addClass(animate+' '+$(this).attr('animateClass')); } }else{ if(animate=="random"||animate.indexOf(',')>=0) { $(this).find($(this).attr('effect')).each(function() { random = Math.floor(Math.random()*(arr.length)); random = arr[random]; $(this).addClass(random+' animated'); }); }else{ $(this).find($(this).attr('effect')).addClass(animate+' animated'); } } }else{ if($(this).attr('animateClass')) { $(this).addClass(animate+' '+$(this).attr('animateClass')); }else{ $(this).addClass(animate+' animated'); } } }); $('[reach]').each(function() { if($(document).scrollTop()+$(window).height()>=$(this).offset().top){ animate = $(this).attr('reach'); if(animate.indexOf(',')>=0){ arr = animate.split(','); }else{ arr = ["fadeIn","zoomIn","fadeInUp","fadeInRight","fadeInDown","fadeInLeft"]; } if($(this).attr("effect")){ effectchild = $(this).attr("effect"); $(this).find(effectchild).each(function() { if(animate=="random"||animate.indexOf(',')>=0) { random = Math.floor(Math.random()*(arr.length)); random = arr[random]; $(this).addClass(random+" animated"); }else{ $(this).addClass(animate+" animated"); } }); $(this).find(effectchild).css({ 'visibility': 'visible' }); }else{ $(this).addClass(animate+" animated"); $(this).css({ 'visibility': 'visible' }); } // $(this).removeAttr('reach'); } }); $(window).scroll(function() { topval = $(document).scrollTop(); $('[reach]').each(function() { if(topval>$(this).offset().top-$(window).height()){ animate = $(this).attr('reach'); if($(this).attr("effect")){ effectchild = $(this).attr("effect"); $(this).find(effectchild).addClass(animate+" animated"); $(this).find(effectchild).css({ 'visibility': 'visible' }); }else{ $(this).addClass(animate+" animated"); $(this).css({ 'visibility': 'visible' }); } }else{ animate = $(this).attr('reach'); if($(this).attr("effect")){ effectchild = $(this).attr("effect"); $(this).find(effectchild).removeClass(animate+" animated"); $(this).find(effectchild).css({ 'visibility': 'hidden' }); }else{ $(this).removeClass(animate+" animated"); $(this).css({ 'visibility': 'hidden' }); } } }); }); } } function dir(e) { console.dir(e); } function log(e) { console.log(e); } function version() { var explorer = window.navigator.userAgent ; if (explorer.indexOf("MSIE") >= 0||explorer.indexOf("Trident")>0 ) { if(explorer.indexOf("MSIE 5")>0||explorer.indexOf("MSIE 6")>0||explorer.indexOf("MSIE 7")>0||explorer.indexOf("MSIE 8")>0) { return 'LowerIEVersion'; }else{ return 'EdgeOrTrident'; } } else if (explorer.indexOf("Maxthon") >= 0) {return 'Maxthon';} else if (explorer.indexOf("Firefox") >= 0) {return 'FireFox';} else if(explorer.indexOf("Chrome") >= 0){ return 'Chrome';} else if(explorer.indexOf("Opera") >= 0){ return 'Opera';} else if(explorer.indexOf("Safari") >= 0){ return 'Safari';} } function mobile() { var userAgentInfo = navigator.userAgent; var Agents = ["Android", "iPhone","SymbianOS", "Windows Phone","iPad", "iPod"]; var flag = false; for (var v = 0; v < Agents.length; v++) { if (userAgentInfo.indexOf(Agents[v]) > 0) { flag = true; break; } } // var isAndroid = userAgentInfo.indexOf('Android') > -1; // var isiOS = !!userAgentInfo.match(/(\(i[^;]+;( U;)? CPU.+Mac OS X)|renrenche/); return flag; } function mousewheel() { $('body').append(repeat('
    ',200)); $('body').mousewheel(function(event, delta) { log(delta); }); } function nicescroll() { $('body').niceScroll({ cursorcolor:"none", background: 'none', cursorwidth: '5', cursorborder:"none", cursorborderradius:"0", cursoropacitymin: '0.5', cursoropacitymax: '1', horizrailenabled: false, smoothscroll: false }); } function banscroll() { if($('body').hasClass('banscroll')) { $('body').getNiceScroll(0).locked = true; }else{ $('body').getNiceScroll(0).locked = false; } } function limit(text,length,overflow) { if(!overflow) { overflow = '...'; } if(!length) { length = 10; } return text.substr(0,length)+overflow; } function repeat(text,x) { var $temp=[]; x|=1; for(var i=0;i<=x;$temp[i++]=''); return $temp.join(text); } var $template = { render: function(tpl,data) { var temp=[]; for(var i=0;i