var $win = $(window).width();
var $hei = $(window).height();
var tools = {
  scrollDiy: function (tar) {
    if (tar && tar.length > 0) {
      if ($win >= 750) {
        $(".ybscroll").mCustomScrollbar({
          scrollButtons: {
            enable: false
          }
        });
      } else {
        $(".ybscroll_move").removeClass("ybscroll")
        $(".ybscroll").mCustomScrollbar({
          scrollButtons: {
            enable: false
          }
        });
      }


    }
  },
  updatePlatform: function () {
    var isMobile = /android|iphone|ipad|ipod/g.test(window.navigator.userAgent.toLowerCase()) || $(window).width() <= 1024;
    var isMac = /mac os x/g.test(window.navigator.userAgent.toLowerCase());
    if (isMobile) {
      $("body").addClass("mobile").removeClass("pc");
    } else {
      $("body").addClass("pc").removeClass("mobile");
    }
  },
  //  动画
  updateAnimate: function () {
    var selector = $(".show-in, .fade-in, .scale-in, .fade-in-up, .fade-in-left, .fade-in-right, .fade-in-down, *[count-up-to], *[count-up-to-p]");
    var wh = $(window).height();
    var st = $(window).scrollTop();
    var offset = 0;
    var space = 150;

    selector.each(function () {
      var _this4 = this;

      var oft = $(this).offset().top - wh - st;
      var delay = parseInt($(this).attr("data-fade-delay"), 10) || 50;

      if (oft < 0 && !$(this).hasClass("show")) {
        $(this).attr("data-faded", true);

        if (oft > -wh) {
          offset += space;
        }

        setTimeout(function () {
          $(_this4).addClass("show");
          window.animateShowCallback && animateShowCallback(_this4);

          if (!$('body[data-page="index"]').length) {
            if ($(_this4).attr("count-up-to")) {
              var to = parseInt($(_this4).attr("count-up-to"));
              var countUp = new CountUp(_this4, to, {
                separator: ""
              });
              if (!countUp.error) {
                countUp.start();
              } else {
                console.error(countUp.error);
              }
            }

            if ($(_this4).attr("count-up-to-p")) {
              var to = parseInt($(_this4).attr("count-up-to-p"));
              var countUp = new CountUp(_this4, to, {
                separator: ""
              });
              if (!countUp.error) {
                countUp.start();
              } else {
                console.error(countUp.error);
              }
            }
          }
        }, $(this).attr("data-fade-immediately") === "true" ? delay : delay + offset);
      }
    });
  },

  setNavBg: function () {
    tools.updatePlatform()
    tools.updateAnimate()
  },
}


$(function () {
  $(window).on("scroll", tools.setNavBg);
  $(window).on("resize", tools.setNavBg);
  tools.setNavBg();

  tools.scrollDiy($(".ybscroll"))



})
