bootstrap-datepicker
bootstrap-datepicker copied to clipboard
position error
Expected behaviour
position error
Actual behaviour
picture is:
Datepicker version used
ex. 1.8.0
Example code
bootstrap-datepicker.js line 673: var left = offset.left - appendOffset.left; left = left + window.screen.width/2 - document.body.clientWidth / 2 ; // add this
bootstrap-datepicker.js line 673: var left = offset.left - appendOffset.left; left = left + window.screen.width/2 - document.body.clientWidth / 2 ; // add this
I had a similar issue where the popup was positioned wrong (on top and a bit to the side of the input element). The cause appeared to be that I had margins on my body element, which caused everything to be shifted by appendOffset, even though the offset itself appeared to be absolute...
Your suggested solution worked if my window was maximized (where window.screen.width and document.body.clientWidth, and the same for heights, were fairly similar in size), but on a smaller window I would get weird offsets again.
Removing the margins from my body element fully resolved this for me.
I had max-width
and margin
on body
as well and therefore the wrong positioning. If you can, wrap everything in some <div id='mainContainer'>
and apply the max-width
and margin
in this div. Works like a charm.