Get the visible height of a div with jQuery

Calculate the amount of px an element (height) is in viewport Fiddle demo This tiny function will return the amount of px an element is visible in the (vertical) Viewport: function inViewport($el) { var elH = $el.outerHeight(), H = $(window).height(), r = $el[0].getBoundingClientRect(), t=r.top, b=r.bottom; return Math.max(0, t>0? Math.min(elH, H-t) : Math.min(b, H)); } Use … Read more

Best way to check if UITableViewCell is completely visible

You can get the rect of a cell with rectForRowAtIndexPath: method and compare it with tableview’s bounds rect using CGRectContainsRect function. Note that this will not instantiate the cell if it is not visible, and thus will be rather fast. Swift let cellRect = tableView.rectForRowAtIndexPath(indexPath) let completelyVisible = tableView.bounds.contains(cellRect) Obj-C CGRect cellRect = [tableView rectForRowAtIndexPath:indexPath]; … Read more

Jquery check if element is visible in viewport [duplicate]

You can write a jQuery function like this to determine if an element is in the viewport. Include this somewhere after jQuery is included: $.fn.isInViewport = function() { var elementTop = $(this).offset().top; var elementBottom = elementTop + $(this).outerHeight(); var viewportTop = $(window).scrollTop(); var viewportBottom = viewportTop + $(window).height(); return elementBottom > viewportTop && elementTop < … Read more