Is in Viewport - Detecta si esta en pantalla

PHOTO EMBED

Wed Nov 18 2020 12:23:04 GMT+0000 (UTC)

Saved by @rstringa #window #viewport

    
    $.fn.visible = function (partial) {
      var $t = $(this),
        $w = $(window),
        viewTop = $w.scrollTop()+130, // 130 because fixed header
        viewBottom = viewTop + $w.height(),
        _top = $t.offset().top,
        _bottom = _top + $t.height(),
        compareTop = partial === true ? _bottom : _top,
        compareBottom = partial === true ? _top : _bottom;

      return compareBottom <= viewBottom && compareTop >= viewTop;
    };

    $(window).scroll(function (event) {
      $(".vertical-scrolling").each(function (i, el) {
        var el = $(el);
        if (el.visible(true)) {
          el.addClass("active");
        } else {
          el.removeClass("active");
        }
      });
content_copyCOPY