$(function (){ if(window.innerWidth >= 1140){ am5.ready(function() { var chart,polygonSeries, beforeCountry, mapTimer, runTimer1, runTimer2, mapTimerLen = $(".relMapEarth-items li").length-1, toBegin = false; am5.ready(function() { var root = am5.Root.new("chartdiv"); root.setThemes([am5themes_Animated.new(root)]); chart = root.container.children.push(am5map.MapChart.new(root, {panX: "rotateX",panY: "rotateY",projection: am5map.geoOrthographic(),paddingTop: 0,paddingRight: 0,paddingBottom: 0,paddingLeft: 0})); root.setThemes([am5themes_Animated.new(root)]); polygonSeries = chart.series.push(am5map.MapPolygonSeries.new(root, {geoJSON: am5geodata_worldLow})); polygonSeries.mapPolygons.template.setAll({fill: am5.color("#ecf2f7"),stroke: am5.color("#ecf2f7")}); var backgroundSeries = chart.series.unshift(am5map.MapPolygonSeries.new(root, {})); backgroundSeries.mapPolygons.template.setAll({fill: am5.color(0xffffff)}); backgroundSeries.data.push({geometry: am5map.getGeoRectangle(90, 180, -90, -180)}); }); $(".relMap-list li").click(function(){ if(!$(this).hasClass("active")){ var _this = $(this); $(".relMap-list li").removeClass("active"); $(this).addClass("active") selectCountry($(this).data("country")) $(".relMapEarth-items li").removeClass("active"); clearTimeout(runTimer1); clearTimeout(runTimer2); if(beforeCountry != $(this).data("country")){ $(".relMapEarth-items li").removeClass("show"); runTimer1 = setTimeout(function(){ $(".relMapEarth-items li[data-country='"+_this.data("country")+"']").addClass("show"); setTimeout(function(){$(".relMapEarth-items li").eq(_this.index()).addClass("active");},444); },1500); }else{ runTimer2 = setTimeout(function(){$(".relMapEarth-items li").eq(_this.index()).addClass("active");},444); } toBegin = true if(toBegin){clearInterval(mapTimer);mapTimerFn(_this.index());} beforeCountry = $(this).data("country"); } }); $(".relMapEarth-items li .relMapEarth-items-info").mouseenter(function(){ var id = $(this).parents("li").index(); $(".relMap-list li").removeClass("active"); $(".relMapEarth-items li").removeClass("active"); if(!$(this).parents("li").hasClass("active")){ clearInterval(mapTimer); $(".relMap-list li").eq(id).addClass("active"); $(".relMapEarth-items li").eq(id).addClass("active"); } }); $(".relMapEarth-items li .relMapEarth-items-info").mouseleave(function(){var id = $(this).parents("li").index();if(id>mapTimerLen){id = 0}mapTimerFn(id+1);}); function selectCountry(id) { var dataItem = polygonSeries.getDataItemById(id); var target = dataItem.get("mapPolygon"); if(target){ var centroid = target.geoCentroid(); if (centroid) { chart.animate({ key: "rotationX", to: -centroid.longitude, duration: 1400, easing: am5.ease.inOut(am5.ease.cubic) }); chart.animate({ key: "rotationY", to: -centroid.latitude + 16, duration: 1400, easing: am5.ease.inOut(am5.ease.cubic) }); } } }; var BoxLeft = 0; setTimeout(function(){mapInfo()},222); function mapInfo(){BoxLeft = $(".relMapEarth-items").offset().left;$(".relMapEarth-items li").each(function(){$(this).find(".relMapEarth-items-info").width($(this).offset().left - BoxLeft)})} $(window).resize(function () {mapInfo()}); var relMapTop = 0, relMapFlag = true; setTimeout(function(){relMapTop = $(".relMap .contain").offset().top - $(window).height();mapLiFn();},222); function mapLiFn(){ if($(window).scrollTop() >= relMapTop && relMapFlag){ relMapFlag = false; setTimeout(function(){$(".relMapEarth-box").addClass("on");$(".relMap-list li").eq(0).trigger("click");setTimeout(function(){$(".relMap-max").addClass("on")},1500);},666); } } $(window).scroll(function () {mapLiFn()}); function mapTimerFn(i){ mapTimer = setInterval(function(){if(i>mapTimerLen){i = 0}$(".relMap-list li").eq(i).trigger("click");i+=1;toBegin = false},3000); } }); }else{ $(".relMap-list li").eq(0).addClass("active"); $(".relMapEarth-items li").eq(0).addClass("active"); $(".relMap-list li").click(function(){ if(!$(this).hasClass("active")){ $(".relMap-list li").removeClass("active"); $(".relMapEarth-items li").removeClass("active"); $(this).addClass("active"); $(".relMapEarth-items li").eq($(this).index()).addClass("active"); } }) } });