So, i have a function that is called via a selector
$(window).scroll(function() {
console.log($("#content div").inview());
});
However it returns undefined. When I return $elems it shows me all correct elements, but when i return $el it gives undefined.
$.fn.inview = function() {
var $elems = this;
function getViewportHeight() {
/*do tsoomething that works*/
return height;
}
var vpH = getViewportHeight(),
scrolltop = (document.documentElement.scrollTop ?
document.documentElement.scrollTop :
document.body.scrollTop);
// return $elems.toArray();
$elems.each(function () {
var $el = $(this)
height = $el.height() - (vpH / 1.5),
inview = $el.data('inview') || false,
topofscreen = scrolltop,
botofscreen = topofscreen + vpH,
topofelement= $el.offset().top;
return $el;
};