对不起,标题戈尔,不知道如何更简洁。Bootstrap模式意外移动,第二次点击
我想要做的事:
我有我希望从多个按钮(动态创建的)调用,位置靠近按钮的模式。使用jQuery,我得到点击按钮的.offset()
,然后将其分配给模态。
Bootply:http://www.bootply.com/lEUtR2IkeU
的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.
});
问题:
第一次任一按钮被点击时,它工作正常(好了,我d宁可显示在上面,但现在足够了),但第二次模式显示,然后它的顶部位置正在增加由13px编辑。
我确定有些事我没有考虑,但我迷路了。我尝试.position(),只是获取/设置CSS顶部和左侧的属性,以及其他许多事情。有时间转向比我更聪明的头脑。
我想通了。也许我的问题还不够清楚,但我希望模式出现在触发它的按钮附近。无论选择哪个按钮,您的答案都会显示在同一高度。感谢您试图帮助! – jreed121