Jquery 引导模式在第二次单击时意外移动
对不起,戈尔的标题,我不知道如何更简洁 我想做什么:Jquery 引导模式在第二次单击时意外移动,jquery,twitter-bootstrap-3,modal-dialog,css-position,offset,Jquery,Twitter Bootstrap 3,Modal Dialog,Css Position,Offset,对不起,戈尔的标题,我不知道如何更简洁 我想做什么: $('.model-open-btn').click(function(){ $('#pageJumpModal').show().height( '1px' ); //#pageJumpModal is the container that's hidden, .offset has problems with hidden elements, so show it first. var offset = $(this).offse
$('.model-open-btn').click(function(){
$('#pageJumpModal').show().height( '1px' ); //#pageJumpModal is the container that's hidden, .offset has problems with hidden elements, so show it first.
var offset = $(this).offset(); //Get the button's offset
$('#pageJumpModal > .modal-dialog').offset({top: offset.top, left: offset.left}); //Set the modal's position.
$('#pageJumpModal').height( 'auto' ).hide(); //Reset the container's height.
});
我有一个模式,我想从多个按钮(动态创建)调用,并定位在按钮附近。使用jQuery,我将获得单击按钮的.offset()
,然后将其分配给模式
Bootply:
JS:
$('.model-open-btn').click(function(){
$('#pageJumpModal').show().height( '1px' ); //#pageJumpModal is the container that's hidden, .offset has problems with hidden elements, so show it first.
var offset = $(this).offset(); //Get the button's offset
$('#pageJumpModal > .modal-dialog').offset({top: offset.top, left: offset.left}); //Set the modal's position.
$('#pageJumpModal').height( 'auto' ).hide(); //Reset the container's height.
});
问题:
$('.model-open-btn').click(function(){
$('#pageJumpModal').show().height( '1px' ); //#pageJumpModal is the container that's hidden, .offset has problems with hidden elements, so show it first.
var offset = $(this).offset(); //Get the button's offset
$('#pageJumpModal > .modal-dialog').offset({top: offset.top, left: offset.left}); //Set the modal's position.
$('#pageJumpModal').height( 'auto' ).hide(); //Reset the container's height.
});
第一次点击任何一个按钮时,它都可以正常工作(好吧,我希望它显示在上面,但现在已经足够好了),但是第二次显示模式时,它的顶部位置增加了13px
我肯定有些事情我没有考虑,但我迷路了。我尝试了.position(),只是获取/设置css的top和left属性,以及其他许多东西。是时候求助于比我更聪明的人了。尝试将高度和顶部位置添加到模式框中 CSS
#pageJumpModal>.modal-dialog {
position: absolute;
width: 160px;
height:160px;
top:50px !important;
}
我希望这会有所帮助,所以问题是
位置:绝对代码>用于.modal对话框
,并且它位于容器内。情态动词基本上应该位于
的末尾,因此它们的位置将与文档相关,而不是其他内容
以下是解决方案:
在我看来,这是一个更好的选择,任何人都有一堆下拉菜单/菜单做类似的事情。我在调用按钮的数据-…
属性中设置值或任何我想更改的关于模式的内容,然后在$中传递值。单击()
(这也可以使用引导的模式事件来完成)。我将其打印出来。也许我的问题不够清楚,但我希望模态显示在触发它的按钮附近。无论选择了哪个按钮,您的答案都会显示在相同的高度。谢谢你的帮助!