Problem with detecting if element is inView
karooolis opened this issue · 1 comments
karooolis commented
On my website I have been experiencing a problem with the script where it doesn't detect correctly whether an element is in view or not. It's because some images on my website ( bredymer.dk/biler.aspx ) return ele.getBoundingClientRect().left value less than zero meaning that their left coordinate starts outside viewport. This has caused some of the images not to load and I fixed it by
I have fixed it by modifying
function elementInView(ele) {
var rect = ele.getBoundingClientRect();
var bottomline = winHeight + options.offset;
return (
// inside horizontal view
rect.left >= -20
&& rect.right <= winWidth + options.offset
&& (
// from top to bottom
rect.top >= 0
&& rect.top <= bottomline
// from bottom to top
|| rect.bottom <= bottomline
&& rect.bottom >= 0 - options.offset
)
);
return inView;
}
where I set rect.left >= -20 . This is not a universal solution and only helped fixed problem in my website. Perhaps there are some universal ways to solve it?
dinbror commented
Fixed in version 1.3.0