元素可见后触发的事件
Event that triggers once an element is made visible
我的项目中有多个bootbox对话框,我希望它们都出现在屏幕的中央,我不能单独去计算每个框的高度并在模态显示时将其定位在中心.有没有一种通用的方法可以做到这一点。有没有办法在 bootbox 可见时触发事件,我试过 'DOMNodeInserted',但这会产生递归错误也试过 livequery,但这没有用。谁能告诉我当对话框在公共点可见时如何触发事件。
jQuery(document).on('DOMNodeInserted', function(e) {
if(jQuery(e.target).hasClass('modal')) {
setTimeout(function(){
if(jQuery(e.target).height()/2 > 1){
var topPos = ((jQuery(window).height() - 30)/2) - jQuery(e.target).find('.modal-dialog').height()/2;
jQuery('.modal-content').css('top', topPos);
}
},200);
}
});
此致,
哪吒
试试这个代码
.on("shown.bs.modal", function(e) {
alert("bootbox is visible");
});
已更新
将引导盒居中对齐
.on("shown.bs.modal", function(e) {
$('.modal-content').css({
'transition':'margin-top 1s linear',
'margin-top': function (){
var w = $( window ).height();
var b = $(".modal-dialog").height();
var h = (w-b)/2;
return h+"px";
}
});
});
我的项目中有多个bootbox对话框,我希望它们都出现在屏幕的中央,我不能单独去计算每个框的高度并在模态显示时将其定位在中心.有没有一种通用的方法可以做到这一点。有没有办法在 bootbox 可见时触发事件,我试过 'DOMNodeInserted',但这会产生递归错误也试过 livequery,但这没有用。谁能告诉我当对话框在公共点可见时如何触发事件。
jQuery(document).on('DOMNodeInserted', function(e) {
if(jQuery(e.target).hasClass('modal')) {
setTimeout(function(){
if(jQuery(e.target).height()/2 > 1){
var topPos = ((jQuery(window).height() - 30)/2) - jQuery(e.target).find('.modal-dialog').height()/2;
jQuery('.modal-content').css('top', topPos);
}
},200);
}
});
此致,
哪吒
试试这个代码
.on("shown.bs.modal", function(e) {
alert("bootbox is visible");
});
已更新
将引导盒居中对齐
.on("shown.bs.modal", function(e) {
$('.modal-content').css({
'transition':'margin-top 1s linear',
'margin-top': function (){
var w = $( window ).height();
var b = $(".modal-dialog").height();
var h = (w-b)/2;
return h+"px";
}
});
});