Skip to content

Commit

Permalink
Merge pull request #2 from kevinmarx/issue-1
Browse files Browse the repository at this point in the history
Fixes #1
  • Loading branch information
kevinmarx authored Oct 15, 2017
2 parents 48327c9 + 56cdfb1 commit 443e09d
Showing 1 changed file with 16 additions and 9 deletions.
25 changes: 16 additions & 9 deletions jquery.overflowing.js
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@
this.options = options || window

this.each(function(){
if ($.isWindow(this)) return false
var $this = $(this)
elPosition = $this.position()
elWidth = $this.width()
Expand All @@ -22,15 +23,21 @@
parents.push($parentsTo)

for(var i=0; i<parents.length; i++){
var parentPosition = $(parents[i]).position()
var parentWidth = $(parents[i]).width()
var parentHeight = $(parents[i]).height()
if ( elPosition.top<0
|| elPosition.left<0
|| elPosition.top>(parentHeight+parentPosition.top)
|| elPosition.left>(parentWidth+parentPosition.left)
|| (elPosition.top + elHeight) > (parentHeight+parentPosition.top)
|| (elPosition.left+elWidth) > (parentWidth+parentPosition.left)){
var $parent = $(parents[i])
if ($.isWindow($parent[0])) break
var absPosition = !!~['absolute', 'fixed'].indexOf($parent.css('position'))
var parentPosition = $parent.position()
var parentWidth = $parent.width()
var parentHeight = $parent.height()
var parentToBottom = absPosition ? parentHeight : (parentHeight+parentPosition.top)
var parentToRight = absPosition ? parentWidth : (parentWidth+parentPosition.left)

if ( elPosition.top < 0
|| elPosition.left < 0
|| elPosition.top > parentToBottom
|| elPosition.left > parentToRight
|| (elPosition.top + elHeight) > parentToBottom
|| (elPosition.left + elWidth) > parentToRight) {
status = true
$(parents[i]).addClass('overflowed')
overflowed.push(parents[i])
Expand Down

0 comments on commit 443e09d

Please sign in to comment.