如何控制jQueryUI datepicker的定位 [英] How to control positioning of jQueryUI datepicker

查看:341
本文介绍了如何控制jQueryUI datepicker的定位的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

jQueryUI中的datepicker呈现动态位置。如果它有足够的空间,它会根据其CSS来渲染,但如果没有足够的窗口空间,它会尝试在屏幕上呈现。我需要它每次保持放置和渲染在同一个地方,独立于屏幕位置或其他情况。 jQueryUI datepicker怎么能这样做? jQuery datepicker的其他实现似乎有这样做的方法,但是我没有看到为UI版本做的方法。

The datepicker in jQueryUI renders with a dynamic position. It renders according to its css if there's enough room for it, but if there isn't enough window space it tries to render on screen. I need it to stay put and render in the same place every time, independent of the screen position or other circumstances. How can this be done with the jQueryUI datepicker? Other implementations of jQuery datepicker seem to have ways of doing this, but I don't see a way of doing it for the UI version.

答案似乎不是修改css:

The answer doesn't seem to be just modifying the css:

.ui-datepicker { width: 17em; padding: .2em .2em 0; (trying top/margin-top/position:relative, etc. here...)}

。 ..since当创建datepicker时,它会在元素样式中动态创建顶部和左侧。还没有找到方法。我看到的一种方法是在beforeShow选项中给出这样的一个方法:

...since when the datepicker is created it dynamically creates top and left in element style. Haven't found a way around this yet. One approach I saw is to give something like this in the beforeShow option:

beforeShow: function(input,inst){
                                inst.dpDiv.css({ 
                                   'top': input.offsetHeight+ 'px', 
                                   'left':(input.offsetWidth - input.width)+ 'px'
                                               });
                                }

这有一些效果,但是顶部和左侧属性仍然在动态设置这是在datepicker渲染时运行的。它仍然在屏幕上渲染。如何让它总是在同一个地方呈现?我的下一步可能是进入叮叮当的胆量,开始拉出来。任何想法?

This has some effect but the top and left properties are still being dynamically set after this is run when the datepicker renders. It's still trying to render on screen. How do I get it to always render in the same spot? My next step is probably to go into the datepicker guts and start pulling things out. Any ideas?

请注意,对于UI版本的答案不在:

Note that the answer (for the UI version) is not in:

  • how-to-change-the-pop-up-position-of-the-jquery-datepicker-control
  • change-the-position-of-jquery-ui-datepicker

推荐答案

发布这个,希望它能帮助别人。至少在datepicker的v1.8.1之前,使用'window.DP_jQuery.datepicker'不再有效,因为现在的指针(右边?)以创建的时间戳命名 - 所以例如现在是'window'。 DP_jQuery_1273700460448'。所以现在,而不是使用指向datepicker对象的指针,直接参考它:

Posting this in hopes that it will help others. At least as of v1.8.1 of datepicker, using 'window.DP_jQuery.datepicker' no longer works, because the pointer(right term?) now is named with a timestamp of its creation - so for example it would now be 'window.DP_jQuery_1273700460448'. So now, rather than using the pointer to the datepicker object, refer to it directly like this:

$.extend($.datepicker,{_checkOffset:function(inst,offset,isFixed){return offset}});

非常感谢以下答案让我得到我所需要的。

Many thanks for the answer below for getting me what I needed.

这篇关于如何控制jQueryUI datepicker的定位的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆