$(function () {
  $(".header_root").load("./sections/comm/header.html");
  $(".footer_root").load("./sections/comm/footer.html");
  // nav传值显示下划线
  $(".header_root").data("nav_info", null);
  let _homeSwiperTimer = null;
  let homeSwiper = new Swiper(".home_swiper_container.swiper-container", {
    loop: true,
    autoplay: 5000,
    // 如果需要分页器
    pagination: ".swiper-pagination",
    autoplayDisableOnInteraction : false,
    paginationType: "custom",
    onSlideChangeStart: function(_swiper){
      if (_homeSwiperTimer) {
        clearInterval(_homeSwiperTimer);
      }
      $(".home_swiper_pagination .pagination_item_progress").each(function(i, element){
        element.style.width = "0%";
      });
    },
    onSlideChangeEnd: function(_swiper){
      if (_homeSwiperTimer) {
        clearInterval(_homeSwiperTimer);
      }
      let _width = 0;
      _homeSwiperTimer = setInterval(function() {
        _width += 1;
        if ($(".home_swiper_pagination .pagination_item_progress")[_swiper.realIndex]) {
          $(".home_swiper_pagination .pagination_item_progress")[_swiper.realIndex].style.width = _width + "%";
          if (_width === 100 && _homeSwiperTimer) {
            clearInterval(_homeSwiperTimer);
          }
        }
      }, 50);
    }
  });
});
