window.onload = function () { var common = { init: function () { this.animation('fadeInUp'); this.animation('fadeInLeft'); this.countUp(); if (this.isMobile()) { this.phoneMenu(); } else { this.pcThreeNav(); } var classifyList = $('.classify-list .classify-list-item'); var classifyText = $('.classify-text'); classifyText.eq(0).addClass('active').siblings().removeClass('active'); classifyList.eq(0).addClass('active').siblings().removeClass('active'); classifyList.click(function () { var _this = $(this); var _index = _this.index(); _this.addClass('active').siblings().removeClass('active'); classifyText.eq(_index).addClass('active').siblings().removeClass('active'); }); }, // 判断是否是移动端 isMobile: function () { if (/Android|webOS|iPhone|iPod|BlackBerry/i.test(navigator.userAgent)) { return true; } else { return false; } }, countUp: function () { var $offsetTop = $(window).height(); $('.js-countUp .count').each(function () { var $this = $(this); $this.waypoint({ handler: function (direction) { if (direction === 'down') { if (!$this.hasClass('active')) { $this.addClass('active'); var end = $this.data('count'); var y = String(end).indexOf(".") + 1;//获取小数点的位置 var count = String(end).length - y;//获取小数点后的个数 if(y > 0) { var countUp = new CountUp($this.find('span')[0], end, { separator: '', decimalPlaces: count }) } else { var countUp = new CountUp($this.find('span')[0], end, { separator: '', decimalPlaces: 0 }) } if (!countUp.error) { countUp.start(); } else { console.error(countUp.error); } } else { $this = null; } } }, offset: $offsetTop, }); }); }, animation: function (className) { var $offsetTop = $(window).height(); var ele = '.js-' + className; var waypoints = $(ele).waypoint({ handler: function (direction) { if (direction === "down") { $(this.element).addClass("animated " + className); } else { $(this.element).removeClass("animated fadeInUp"); } }, offset: $offsetTop, }); }, pcThreeNav: function () { if ($('.js-three').length > 0) { $('.js-three .tow-list-item').mouseover(function () { var height = $(this).find('.three-nav').outerHeight(true); $('.js-three').css('min-height', height); $(this).addClass('active').siblings().removeClass('active'); }).eq(0).trigger('mouseover'); $('.js-hover dd').hover(function () { $(this).addClass('active').siblings().removeClass("active"); }); } }, phoneMenu: function () { var $phoneMenu = $('.ty-phone-header'), $phoneNav = $('.phone-nav'), $dropNav = $phoneNav.find('.down-nav'); $dropNav.each(function () { var $this = $(this); if ($this.find('.tow-list-item').length > 0) { $this.parent('li').addClass('dropdown'); } }) $('.dropdown>a').on('click', function () { $(this).siblings('.down-nav').slideToggle(); $(this).parent('.dropdown').siblings().find('.down-nav').slideUp(); $('.three-nav').slideUp(); }); $('.three-border a').on('click', function () { $(this).siblings('.three-nav').slideToggle(); $(this).parent('.tow-list-item').siblings().find('.three-nav').slideUp(); }) $phoneMenu.click(function () { $phoneNav.addClass('active'); $('.phone-mask-layer').fadeIn(300); }); $('.js-colse-menu').click(function () { $phoneNav.removeClass('active'); $('.phone-mask-layer').fadeOut(300); }); $('.js-swiper-btn .tow-list-item').click(function () { $phoneNav.removeClass('active'); $('.phone-mask-layer').fadeOut(300); }); }, } common.init(); }