-
-
Save scopevale/db5638ec7f5cacbbb77b to your computer and use it in GitHub Desktop.
This file contains hidden or 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 inView(el, fn) { | |
var location, size; | |
el.getCssValue('display') | |
.then(function (display) { | |
if (display === 'none') { | |
fn(false); | |
} else { | |
return el.getSize() | |
} | |
}) | |
.then(function (s) { | |
if (!s.width || !s.height) { | |
fn(false); | |
} else { | |
size = s | |
return el.getCssValue('position') | |
} | |
}) | |
.then(function (position) { | |
if( position === "absolute" ){ | |
var location = { | |
x: 0, | |
y: 0 | |
}; | |
return el.getCssValue('top').then(function(top){ | |
location.y = top.replace('px', ''); | |
return el.getCssValue('left') | |
}) | |
.then(function(left){ | |
location.x = left.replace('px', ''); | |
return location | |
}) | |
}else { | |
return el.getLocation() | |
} | |
}) | |
.then(function (loc) { | |
if(loc !== undefined) { | |
if (loc.x + size.width <= 0 || loc.y + size.height <= 0) { | |
fn(false); | |
} | |
} | |
}) | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment