I am trying to determine which% of the item can be seen in the current window.
For example, if the user can only see half of the item, return 50. If the user can see the whole item, return 100.
Here is my code:
function getPercentOnScreen() {
var $window = $(window),
viewport_top = $window.scrollTop(),
viewport_height = $window.height(),
viewport_bottom = viewport_top + viewport_height,
$elem = $(this),
top = $elem.offset().top,
height = $elem.height(),
bottom = top + height;
return (bottom - viewport_top) / height * 100;
}
But it does not seem to work. Can anyone help me with this, I seem to be spinning.
source
share