(function($) { $.belowthefold = function(element, settings) { var fold = $(window).height() + $(window).scrolltop(); return fold <= $(element).offset().top - settings.threshold; }; $.abovethetop = function(element, settings) { var top = $(window).scrolltop(); return top >= $(element).offset().top + $(element).height() - settings.threshold; }; $.rightofscreen = function(element, settings) { var fold = $(window).width() + $(window).scrollleft(); return fold <= $(element).offset().left - settings.threshold; }; $.leftofscreen = function(element, settings) { var left = $(window).scrollleft(); return left >= $(element).offset().left + $(element).width() - settings.threshold; }; $.inviewport = function(element, settings) { return !$.rightofscreen(element, settings) && !$.leftofscreen(element, settings) && !$.belowthefold(element, settings) && !$.abovethetop(element, settings); }; $.extend($.expr[':'], { "below-the-fold": function(a, i, m) { return $.belowthefold(a, {threshold : 0}); }, "above-the-top": function(a, i, m) { return $.abovethetop(a, {threshold : 0}); }, "left-of-screen": function(a, i, m) { return $.leftofscreen(a, {threshold : 0}); }, "right-of-screen": function(a, i, m) { return $.rightofscreen(a, {threshold : 0}); }, "in-viewport": function(a, i, m) { return $.inviewport(a, {threshold : 0}); } }); })(jquery); jquery(document).ready(function ($) { var gt_ios8 = false; // 判断是否 ios设备 if ((navigator.useragent.match(/iphone/i) || navigator.useragent.match(/ipad/i))) { // 判断系统版本号是否大于 8 if (navigator.useragent.match(/os [8-9]_\d[_\d]* like mac os x/i)) { gt_ios8 = true; $("body").addclass("ios8"); } } // !- skills $.fn.animateskills = function () { $(".skill-value", this).each(function () { var $this = $(this), $this_data = $this.data("width"); $this.css({ width: $this_data + '%' }); }); }; // !- animation "onscroll" loop function doanimation() { var j = -1; $(".anim_emt:not(.start-animation):in-viewport").each(function () { var $this = $(this); if (!$this.hasclass("start-animation") && !$this.hasclass("animation-triggered")) { $this.addclass("animation-triggered"); j++; settimeout(function () { $this.addclass("start-animation"); if ($this.hasclass("skills")) { $this.animateskills(); }; }, 200 * j); }; }); }; // !- fire animation if ($("html").hasclass("no-touch") && $("html").hasclass("cssanimations")) { doanimation(); $(window).on("scroll", function () { doanimation(); }); }; });