Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- _getPercentInView = function(element){
- $element = $(element);
- var pos = $element.offset(),
- theViewport = {top:null, left:null, bottom:null, right:null, width:null, height:null},
- theElement = {top:null, left:null, bottom:null, right:null, width:null, height:null},
- elemLeft = pos.left,
- elemTop = pos.top,
- elemHeight = $element.height(),
- elemWidth = $element.width();
- theViewport.width = $(window).width();
- theViewport.height = $(window).height();
- theViewport.top = $(window).scrollTop();
- theViewport.left = $(window).scrollLeft();
- theViewport.bottom = theViewport.top+theViewport.height;
- theViewport.right = theViewport.left+theViewport.width;
- theElement.top = elemTop - theViewport.top;
- theElement.left = elemLeft - theViewport.left;
- theElement.width = elemWidth;
- theElement.height = elemHeight;
- theElement.bottom = theElement.top+theElement.height;
- theElement.right = theElement.left+theElement.width;
- var nPercentInView = Math.round(100 * ((theElement.height-(Math.max(0,0-theElement.top) + Math.max(0,theElement.bottom-theViewport.height))) / theElement.height) * ((theElement.width-(Math.max(0,0-theElement.left) + Math.max(0,theElement.right-theViewport.width))) / theElement.width) );
- return nPercentInView;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement