Created
February 27, 2017 16:25
-
-
Save emersonbroga/619084f79f21a0e97bbc343fb6c52cdf to your computer and use it in GitHub Desktop.
Check if element is visible (in view)
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
function Utils() {} | |
Utils.prototype = { | |
constructor: Utils, | |
isElementInView: function (element, fullyInView) { | |
var pageTop = $(window).scrollTop(); | |
var pageBottom = pageTop + $(window).height(); | |
var elementTop = $(element).offset().top; | |
var elementBottom = elementTop + $(element).height(); | |
if (fullyInView === true) { | |
return ((pageTop < elementTop) && (pageBottom > elementBottom)); | |
} else { | |
return ((elementTop <= pageBottom) && (elementBottom >= pageTop)); | |
} | |
} | |
}; | |
var Utils = new Utils(); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment