title: Checking if an element is visible within a scrollable div
body: <p>First off, this may be considered a duplicate question - however no answer was provided to the one I found when searching:
  <a href="https://stackoverflow.com/questions/34843489/jquery-check-if-element-is-visible-inside-scrollable-div">jQuery check if element is visible inside scrollable div</a></p>
  
  <p>I can't seem to find a solution for checking if an element is visible within a parent div that has a scroll bar, there are obviously ways to do this with the offset being from the parent element, but I was looking whether there was an all around solution that would check each of the same selector wrapped up as a plugin so it can be checked constantly.</p>
  
  <p>The current plugin I am using is limited to the actual window viewport and I don't believe it's possible to alter it to work for a scrollable div.</p>
  
  <p>Current code:</p>
  
  <pre><code>;(function($, win) {
    $.fn.inViewport = function(cb) {
       return this.each(function(i,el){
         function visPx(){
           var H = $(this).height(),
               r = el.getBoundingClientRect(), t=r.top, b=r.bottom;
           return cb.call(el, Math.max(0, t&gt;0? H-t : (b&lt;H?b:H)));  
         } visPx();
         $(win).on("resize scroll", visPx);
       });
    };
  }(jQuery, window));
  </code></pre>