bootstrap datetimepicker控件位置異常的解決方法
今天在寫畢設(shè)的時(shí)候,用到了bootstrap-datetimepicker作為日期控件。
在git上clone下最新的代碼,運(yùn)行demo,發(fā)現(xiàn)控件區(qū)域整體下移1000px左右。
作為一個(gè)準(zhǔn)備拿來就用的后臺(tái)程序猿,此刻我的內(nèi)心是崩潰的…
百度了很久,沒有找到對(duì)應(yīng)的解決方案,于是自己動(dòng)手去源碼修改。
最終解決方案:
打開源碼,的bootstrap-datetimepicker.js文件
line 527行,打開這一段注釋即可
/*if (this.pickerPosition == 'top-left' || this.pickerPosition == 'top-right') {
top = offset.top - this.picker.outerHeight();
} else {
top = offset.top + this.height;
}*/
如果看著還是不是很舒服的話,建議注釋掉line 533 - line 544
top = top - containerOffset.top + 169; left = left - containerOffset.left + 210;
為什么要這樣解決呢?
place: function () {
if (this.isInline) return;
if (!this.zIndex) {
var index_highest = 0;
$('div').each(function () {
var index_current = parseInt($(this).css('zIndex'), 10);
if (index_current > index_highest) {
index_highest = index_current;
}
});
this.zIndex = index_highest + 10;
}
var offset, top, left, containerOffset;
if (this.container instanceof $) {
containerOffset = this.container.offset();
} else {
containerOffset = $(this.container).offset();
}
if (this.component) {
offset = this.component.offset();
left = offset.left;
if (this.pickerPosition == 'bottom-left' || this.pickerPosition == 'top-left') {
left += this.component.outerWidth() - this.picker.outerWidth();
}
} else {
offset = this.element.offset();
left = offset.left;
}
var bodyWidth = document.body.clientWidth || window.innerWidth;
if (left + 220 > bodyWidth) {
left = bodyWidth - 220;
}
/*if (this.pickerPosition == 'top-left' || this.pickerPosition == 'top-right') {
top = offset.top - this.picker.outerHeight();
} else {
top = offset.top + this.height;
}*/
top = top - containerOffset.top + 169;
left = left - containerOffset.left + 210;
this.picker.css({
top: top,
left: left,
zIndex: this.zIndex
});
},
上面就是相關(guān)的源碼,可以看到,注釋了line 527行之后,在后面引用了一個(gè)未初始化過的top變量
嗯… 這是一個(gè)沒經(jīng)過測(cè)試就提交的小BUG…
以上就是本文的全部?jī)?nèi)容,希望對(duì)大家的學(xué)習(xí)有所幫助,也希望大家多多支持腳本之家。
- Bootstrap時(shí)間選擇器datetimepicker和daterangepicker使用實(shí)例解析
- angularjs封裝bootstrap時(shí)間插件datetimepicker
- bootstrap datetimepicker日期插件超詳細(xì)使用方法介紹
- Bootstrap3 datetimepicker控件使用實(shí)例
- bootstrap datetimepicker日期插件使用方法
- bootstrap-datetimepicker實(shí)現(xiàn)只顯示到日期的方法
- Bootstrap 設(shè)置datetimepicker在屏幕上面彈出設(shè)置方法
- bootstrap datetimepicker實(shí)現(xiàn)秒鐘選擇下拉框
- vue2.0 與 bootstrap datetimepicker的結(jié)合使用實(shí)例
- 基于bootstrap-datetimepicker.js不支持IE8的快速解決方法
相關(guān)文章
Javascript驗(yàn)證用戶輸入U(xiǎn)RL地址是否為空及格式是否正確
這篇文章主要介紹了Javascript驗(yàn)證用戶輸入U(xiǎn)RL地址是否為空及格式是否正確,很實(shí)用,需要的朋友可以參考下2014-10-10
純css+js寫的一個(gè)簡(jiǎn)單的tab標(biāo)簽頁(yè)帶樣式
最近經(jīng)常要用tab標(biāo)簽頁(yè),于是就寫了一個(gè)簡(jiǎn)單的tab標(biāo)簽頁(yè),純css+js寫的,帶樣式。大家可以參考下2014-01-01
JavaScript采用遞歸算法計(jì)算階乘實(shí)例
這篇文章主要介紹了JavaScript采用遞歸算法計(jì)算階乘,簡(jiǎn)單分析了javascript遞歸算法的相關(guān)使用技巧,具有一定參考借鑒價(jià)值,需要的朋友可以參考下2015-08-08
javascript 中設(shè)置window.location.href跳轉(zhuǎn)無效問題解決辦法
這篇文章主要介紹了javascript 中設(shè)置window.location.href跳轉(zhuǎn)無效問題解決辦法的相關(guān)資料,需要的朋友可以參考下2017-02-02

