/*! * jquery.inview 互換シム(IntersectionObserver版) * 既存の $(el).on('inview', function(event, isInView){ ... }) がそのまま動作します。 * 旧 jquery.inview.min.js と差し替えるだけで、HTML・bs.js の変更は不要です。 */ (function ($) { 'use strict'; if (!$) return; /* IntersectionObserver非対応の旧ブラウザは「表示扱い」で1回発火(フェイルセーフ) */ if (!('IntersectionObserver' in window)) { $.event.special.inview = { setup: function () { var el = this; setTimeout(function () { $(el).trigger('inview', [true]); }, 0); } }; return; } var io = new IntersectionObserver(function (entries) { entries.forEach(function (entry) { $(entry.target).trigger('inview', [entry.isIntersecting]); }); }, { threshold: 0 }); /* on('inview')で監視開始、off('inview')で監視解除(jQuery special event) */ $.event.special.inview = { setup: function () { io.observe(this); }, teardown: function () { io.unobserve(this); } }; })(window.jQuery);