使用jQuery获取Boostrap模式位置
在我的代码中,如果您单击模式中的按钮,我试图让它警告模式的左/顶部位置,但是它总是返回为0 我不知道为什么浏览器不能返回这些值使用jQuery获取Boostrap模式位置,jquery,twitter-bootstrap,Jquery,Twitter Bootstrap,在我的代码中,如果您单击模式中的按钮,我试图让它警告模式的左/顶部位置,但是它总是返回为0 我不知道为什么浏览器不能返回这些值 $(窗口).on('load',function()){ $('myModal').modal('show'); }); 函数getPos(){ 警报(“顶部:+$(“#myModal”).position().顶部+”左侧:+$(“#myModal”).position().Left); } 情态动词 &时代; ... 点击我 您试过了吗? 希望它能帮助你 HTM
$(窗口).on('load',function()){
$('myModal').modal('show');
});
函数getPos(){
警报(“顶部:+$(“#myModal”).position().顶部+”左侧:+$(“#myModal”).position().Left);
}
情态动词
&时代;
...
点击我
您试过了吗?
希望它能帮助你
HTML
<div class="modal fade" id="myModal" tabindex="-1" role="dialog" aria-labelledby="exampleModalLabel" aria-hidden="true">
<div class="modal-dialog" role="document">
<div class="modal-content">
<div class="modal-header">
<h5 class="modal-title" id="exampleModalLabel">Modal</h5>
<button type="button" class="close" data-dismiss="modal" aria-label="Close">
<span aria-hidden="true">×</span>
</button>
</div>
<div class="modal-body">
...
</div>
<div class="modal-footer">
<button type="button" id="clickMe">Click Me</button>
</div>
</div>
</div>
</div>
或者,请参见此处非常简单地了解为什么您要检查应用的实时html和css规则 modal类创建覆盖,并具有以下主要规则:
.modal {
position: fixed;
top: 0;
right: 0;
bottom: 0;
left: 0;
z-index: 1050;
display: none;
overflow: hidden;
outline: 0;
}
您需要的是子模式对话框的偏移量
$(窗口).on('load',function()){
$('myModal').modal('show');
});
函数getPos(){
$dialog=$(“#myModal.modal dialog”)
警报(“顶部:+$dialog.offset().顶部+”左侧:“+$dialog.offset().Left”);
}
情态动词
&时代;
...
点击我
问题出在offset()左侧的零件上。它只是在引导模式上不断返回0
的值。第二个版本将淘汰jQueryUI插件
.modal {
position: fixed;
top: 0;
right: 0;
bottom: 0;
left: 0;
z-index: 1050;
display: none;
overflow: hidden;
outline: 0;
}