Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- // Returns the coordinates of the two points defining the position of container e
- function getRect(e){
- var eo = $(e).cumulativeOffset(); // element offsets
- return {top: eo.top,
- left: eo.left,
- bottom: eo.top + $(e).getHeight(),
- right: eo.left + $(e).getWidth()};
- }
- function inViewport(e){
- // NOTE: Methods on document.viewport need a proper DOCTYPE cause browsers' quirks mode
- // actually breaks the box model.
- var myCoors = getRect(e);
- console.log(myCoors);
- var so = document.viewport.getScrollOffsets();
- var a = document.viewport.getHeight() + so.top;
- var b = document.viewport.getWidth() + so.left;
- var cond1 = (a > myCoors.bottom) && (b > myCoors.right);
- var cond2 = (myCoors.top > so.top) && (myCoors.left > so.left);
- return (cond1 && cond2);
- }
Add Comment
Please, Sign In to add comment