admin管理员组文章数量:1415476
Here's the code that is generated by default
<div id="ui-datepicker-div" class="ui-datepicker
ui-widget ui-widget-content ui-helper- clearfix ui-corner-all
ui-datepicker-multi ui-datepicker-multi-2" style="width: 34em;
position: absolute; left: 349px; top: 453px; z-index: 1; display: block; ">
The problem with this is that the datepicker is shown right next to the trigger input, instead of the center which is where i want it.
You can see the demo site here: .php
Does anyone know how to center the .ui-datepicker
class using javascript? CSS Won't work, obviously.
Here's the code that is generated by default
<div id="ui-datepicker-div" class="ui-datepicker
ui-widget ui-widget-content ui-helper- clearfix ui-corner-all
ui-datepicker-multi ui-datepicker-multi-2" style="width: 34em;
position: absolute; left: 349px; top: 453px; z-index: 1; display: block; ">
The problem with this is that the datepicker is shown right next to the trigger input, instead of the center which is where i want it.
You can see the demo site here: http://enniakiosk.spin-demo./travelers.php
Does anyone know how to center the .ui-datepicker
class using javascript? CSS Won't work, obviously.
- Center vertically or horizontally? – Sammy Commented May 7, 2012 at 19:52
- Both vertically and horizontally :) – imjp Commented May 7, 2012 at 19:58
- stackoverflow./questions/662220/… - it looks like people think that css will work. – Ben Barden Commented May 7, 2012 at 20:22
2 Answers
Reset to default 3If you're using the .dialog
method it accepts a parameter, pos
which is an [x, y]
array of coordinates (top/left) of where you would like the dialog to appear.
This solution requires that you calculate top and left values such that the dialog looks centered on the page. This depends on how big the box is and what size the viewport is, which you can determine by $(window).height()
and $(window).width()
. You'll have to generate this on the fly.
A quick and dirty way to acplish what you want could be done via CSS. You could either directly override the jquery UI style or add some to your own stylesheet. This relies on using "!important" but it works and you're not digging into the UI code.
Here's what you could add to your own stylesheet. You'll need to the size of the datepicker you're generating. Here's I'm just using the size of the generic demo.
#ui-datepicker-div {
position: absolute !important;
left: 50% !important;
top: 50% !important;
margin-left: -96px; /* approx half the height of the datepicker div - adjust based on your size */
margin-top: -73px; /* half the height of the datepicker div - adjust based on your size */
}
Using "!important" in CSS is a crutch that should be avoided, but just showing how it could be done...
本文标签: javascriptDisplaying jQuery39s Datepicker in the center of the screenStack Overflow
版权声明:本文标题:javascript - Displaying jQuery's Datepicker in the center of the screen - Stack Overflow 内容由网友自发贡献,该文观点仅代表作者本人, 转载请联系作者并注明出处:http://www.betaflare.com/web/1745167185a2645752.html, 本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌抄袭侵权/违法违规的内容,一经查实,本站将立刻删除。
发表评论