var isAnimationPlaying = false; //动画是否正在播放中 $(function () { /*滚动条美化*/ $(".auto-scroll").mCustomScrollbar({ scrollbarPosition: 'inside', autoHideScrollbar: true, scrollInertia: 150, theme: 'minimal', callbacks: { whileScrolling: function () { if ($(this).attr('id') == 'history-scroll') { historyScrollTo(); } /* 品牌历史头部导航淡入淡出效果 */ if ($(this).attr('id') == 'brand-history-scroll') { var m = Math.abs(this.mcs.top); var h = $(this).find('.banner').height() - 10; if (m > h) { $('.timeline-header').fadeIn(); } else { $('.timeline-header').fadeOut(); } historyScrollTo(); } /* 日慈滚动到底部触发动画 */ if ($(this).attr('id') == 'csr-scroll') { if (isAnimationPlaying) { return false; } var nScrollHight = this.mcs.content[0].scrollHeight; //滚动距离总长(注意不是滚动条的长度) var nScrollTop = Math.abs(this.mcs.top); //滚动到的当前位置 var nDivHight = $(this).height(); if (nScrollTop + nDivHight >= nScrollHight) { isAnimationPlaying = true; $('.amount').each(function (index) { var number = 0; if (index == 0) { number = 30; } else if (index == 1) { number = 907022; } else if (index == 2) { number = 15004; } else if (index == 3) { number = 3441; } else if (index == 4) { number = 110; } var elementWidth = $(this).width(); if (index > 0) { $(this).parent().width(elementWidth); } $('.data-block ul').fadeIn(1000); var number_counter = new CountUp(this, 0, number, 0, 2, { useGrouping: false }); var _this = $(this); setTimeout(function () { !number_counter.error && number_counter.start(function () { if (index >= 0) { var realText = number + '+'; _this.text(realText); } isAnimationPlaying = false; }); }, 1000); }); } else { $('.data-block ul').fadeOut(1000); } } } } }); /*头部导航菜单*/ var nav = {}; $('.nav-level-1 > dd').hover(function () { var _nav = $(this).index(); clearTimeout(nav['timer' + _nav]); var _this = $(this); nav['timer' + _nav] = setTimeout(function () { _this.find('.nav-level-2').stop(true, true).fadeIn(200); }, 150); }, function () { var _nav = $(this).index(); clearTimeout(nav['timer' + _nav]); var _this = $(this); nav['timer' + _nav] = setTimeout(function () { _this.find('.nav-level-2').stop(true, true).fadeOut(200); }, 150); }); /*导航hover显示菜单*/ $(".nav-level-2 dd > a").hover(function () { $(this).closest('dl').find('.nav-level-3').hide(); $(this).next().show(); }); /*nav子菜单宽度用于对齐*/ $('.nav-level-box-2').css('width', ($(".nav-level-1").width() - 30) + 'px'); /*微信二维码显示关闭*/ $(".wechat-qrcode-close").on('click', function () { $('.wechat-qrcode-block').fadeOut(); return false; }); $(".qrcode").on('click', function () { var img = $(this).children('img').attr('src'); if (!img) { return false; } $('.wechat-qrcode-block .wechat-qrcode img').attr('src', img); var title = $(this).data('title'); title = title ? title : '手机微信扫码,关注公众号'; $('.wechat-qrcode-block p').text(title); $('.wechat-qrcode-block').fadeIn(); return false; }); $(".share-icon").hover(function () { $(this).removeClass('close-share').addClass('open-share'); }, function () { $(this).removeClass('open-share').addClass('close-share'); }); /*搜索点击*/ $('.header.default .header-right .search').on('click', function () { $(this).parent().addClass('header-hide'); $(this).parent().prev().children('.nav-level-1').removeClass('header-show').addClass('header-hide'); $(this).parent().prev().children('.header-search').removeClass('header-hide').addClass('header-show'); }); $('.header.default .header-search .close').on('click', function () { $(this).closest('.header-search').removeClass('header-show').addClass('header-hide'); $(this).closest('.header-search').prev().removeClass('header-hide').addClass('header-show'); $(this).closest('.nav').next().removeClass('header-hide').addClass('header-show'); }); $('.header.black .header-right .search').on('click', function () { $(this).parent().removeClass('header-show').addClass('header-hide'); $(this).parent().prev().children('.nav-level-1').children('dd').removeClass('.header-show').addClass('header-hide'); $(this).parent().prev().children('.header-search').removeClass('header-hide').addClass('header-show'); }); $('.header.black .header-search .close').on('click', function () { $(this).closest('.header-search').removeClass('header-show').addClass('header-hide'); $(this).closest('.header-search').prev().children('dd').removeClass('header-hide').addClass('header-show'); $(this).closest('.nav').next().removeClass('header-hide').addClass('header-show'); }); $('.header-search-input').on('keyup', function (event) { if (event.keyCode == "13") { window.location.href = headerSearchUrl + '?keyword=' + $(this).val(); } }); /* 历史头部导航定位 */ function historyScrollTo() { var menu = $(".timeline-header"); var items = $(".content").find(".item"); var top = $(document).scrollTop(); var currentId = ""; items.each(function () { var m = $(this); var itemTop = m.offset().top; if (itemTop == 0) { return false; } if (top > itemTop - 100) { currentId = m.attr("id").replace("item", ""); } else { return false; } }); var currentLink = menu.find(".selected"); if (currentId && currentLink.index() + 1 != currentId) { currentLink.removeClass("selected"); menu.find('li:eq(' + (currentId - 1) + ')').addClass("selected"); } } /* 字长截取 */ function cutString(str, len) { var str_length = 0; var str_len = 0; str_cut = new String(); str_len = str.length; for (var i = 0; i < str_len; i++) { a = str.charAt(i); str_length++; if (escape(a).length > 4) { //中文字符的长度经编码之后大于4 str_length++; } str_cut = str_cut.concat(a); if (str_length >= len) { str_cut = str_cut.concat("..."); return str_cut; } } //如果给定字符串小于指定长度,则返回源字符串; if (str_length < len) { return str; } } $(".show-content p").each(function () { var pStr = $(this).text(); $(this).text(cutString(pStr, 246)); }); /* 小标题有无 */ $(".show h3").each(function () { var pStr = $(this).text(); if (pStr == '') { $(this).remove(); } }); /* SLIDER组件 BEGIN */ (function ($) { $('.brand-carousel').on('click', '.show-slider', function () { $.ajax({ type: "GET", url: collectionUrl + "?id=" + $(this).data('id'), dataType: "json", success: function (data) { if (data) { if ((data['collection_type'] == 1 && data['images'].length == 0) || (data['collection_type'] == 3 && data['images'].length == 0) || (data['collection_type'] == 2 && data['collection_video_url'] == '')) { return false; } if (data['on_slide_show'] == 1) { $('.article-header h2').html((data['brand']['brand_name'] + ' | ' + data['collection_date'] + data['collection_name']) || ' '); $('.article-aside h3').html(data['collection_sub_name'] || ' '); $('.article-section').html(data['collection_description'] || ' '); } else { $(".entry-container").hide(); } $(".imgs-slider").css('display', 'block'); if (data['collection_type'] == 1 || data['collection_type'] == 3) { initSlider(data); } else { initVideo(data); } } } }); }); $('.slider-content').on('afterChange', function (event, slick, currentSlide) { $('.series-description strong').text(currentSlide + 1); }); function initSlider(data) { $(".slider-player").show(); $('.show-video').hide(); var html = ""; for (var i = 0; i < data['images'].length; i++) { html += '