First I think there should be a afterShowing method in the datepicker object, where you could change the position after jquery has done all its voodoo in the_showDatepicker method. Additionally, a parameter calledpreferedPosition
would be also desirable, so you could set it and jquery modify it in case the dialog is rendered outside the viewport.
There's a "trick" to do this last thing. If you study the _showDatepicker method, you will see the use of a private variable$.datepikcer._pos. That variable will be setup if nobody has set it up before. If you modify that variable
before showing the dialog, Jquery will take it and will try to allocate the dialog in that position, and if it renders out of the screen, it will adjust it to make sure it is visible. Sounds good, eh?
Problem is; _pos is private, but if you don't mind that. You can:
$('input.date').datepicker({
beforeShow: function(input, inst)
{
$.datepicker._pos = $.datepicker._findPos(input); //this is the default position
$.datepicker._pos[0] = whatever; //left
$.datepicker._pos[1] = whatever; //top
}
});
But be careful of Jquery-ui updates, because a change in the internal implementation of the_showDatepicker might break your code.
mycode:
本文介绍了一种在jQuery UI日期选择器中调整弹出框位置的方法,并提供了一个示例代码来展示如何设置日期选择器的位置及字体大小。
387

被折叠的 条评论
为什么被折叠?



