diff --git a/src/js/select2/dropdown/attachBody.js b/src/js/select2/dropdown/attachBody.js index ec9fa437..667596df 100644 --- a/src/js/select2/dropdown/attachBody.js +++ b/src/js/select2/dropdown/attachBody.js @@ -3,7 +3,7 @@ define([ '../utils' ], function ($, Utils) { function AttachBody (decorated, $element, options) { - this.$dropdownParent = options.get('dropdownParent') || document.body; + this.$dropdownParent = options.get('dropdownParent') || $(document.body); decorated.call(this, $element, options); } @@ -157,6 +157,14 @@ define([ top: container.bottom }; + // Fix positioning with static parents + if (this.$dropdownParent[0].style.position !== 'static') { + var parentOffset = this.$dropdownParent.offset(); + + css.top -= parentOffset.top; + css.left -= parentOffset.left; + } + if (!isCurrentlyAbove && !isCurrentlyBelow) { newDirection = 'below'; }