javascript - 固定位置在 IE 10 与 Bootstrap Modal 中的 Chrome 和 Firefox 中表现不同

标签 javascript html css twitter-bootstrap

We have some popup pickers, and the one edge case that this code isn't working for is internet explorer when the picker is inside a bootstrap modal... To me it looks like chrome and firefox is left relative to the edge模态的,但即相对于页面的边缘。

.pickerModal
{
background-color: #fff;
display: none;
position: fixed;
width: auto;
min-width: 150px;
max-height: 150px;
overflow-y: scroll;
overflow-x: hidden;
border: solid rgba(103,103,103,1) 2px;
-moz-border-radius: 3px;
-webkit-border-radius: 3px;
border-radius: 3px;
z-index: 1051 !important;
padding: 0;
}

self.positionPicker = function (launchSelector, modal, modalPointer) {  

    var gCoord = launchSelector.localToGlobal(0, 0);
    var modalOffset = { top: 0, left: 0 };
    var modalWidth = 0;
    var scroll = document.documentElement.scrollTop || document.body.scrollTop;     

    if ($(launchSelector).closest('.modal-dialog').length) {

        var bootstrapModal = $($(launchSelector).closest('.modal-dialog')[0]);

        modalOffset = bootstrapModal.offset();
        modalWidth = bootstrapModal.width();

    }

    modalPointer.css({
        "top": (gCoord.y + launchSelector.height()) - modalOffset.top - scroll,
        "left": gCoord.x - modalOffset.left
    });

    if (modalWidth == 0) {
        modal.css({
            "top": (gCoord.y + launchSelector.height() + 7) - modalOffset.top - scroll,
            "left": (gCoord.x + modal.width()) > (window.screen.availWidth - 15) ? gCoord.x - ((gCoord.x + modal.width()) - modalOffset.left - (window.screen.availWidth - 15)) : gCoord.x
        });
    } else {            

        modal.css({
            "top": (gCoord.y + launchSelector.height() + 7) - modalOffset.top - scroll,
            "left": gCoord.x + modalOffset.left + modal.width() < $(window).width() ? Math.max(0, gCoord.x - modalOffset.left) : Math.max(0, gCoord.x - modalOffset.left - modal.width() + 10)
        });
    }

    if (modal.position().top < 0) {
        self.hideModal(self.modal());
    }

}

最佳答案

找到答案:

/** 
* This is needed so that the pickers position correctly in all browsers in  modal or non modal windows.  
* Bootstrap css has some magic that makes fixed position elements relative to modal instead of page in chrome and firefox.
*/
.modal.in .modal-dialog 
{ 
 -moz-transform: none;
 -ms-transform: none;
 -o-transform: none;
 -ms-transform: none;
 transform: none;
}

关于javascript - 固定位置在 IE 10 与 Bootstrap Modal 中的 Chrome 和 Firefox 中表现不同,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/28864370/

相关文章:

javascript - 如何在Google图像搜索API v2中获取图像URL

html - 在 Flexbox 中包含 SVG 图像

c++ - 使用 pugixml 或实际的 HTML 解析器解析 HTML

javascript - 当执行这个特定的 onclick 事件时如何执行 JavaScript 函数?

html - Chrome 特定的 CSS 问题设置表单元格显示 :block

javascript - 在 React.JS 中围绕组件共享对象

javascript - 类型错误 : Cannot read property 'name' of null in react with redux

javascript - javascript 中的函数标识

javascript - 仅在页面初始加载时启动 Pace.js

javascript - 动画范围从宽度 0 到自动