$("#youModel").on("shown.bs.modal", function (e) css("display"{var modalHeight=$(window).height() / 2 - $("#youModel .modal-dialog").height() / 2;$(this).find(".modal-dialog").css({ "margin-top": modalHeight}); });会出现问题,每次触发事件让模态框显示的时候,会闪动一下,影响体验,在此查阅资料在此基础上提出完善的方法2
$("#youModel").on("shown.bs.modal", function (e) { // 关键代码,如没将modal设置为 block,则$modala_dialog.height() 为零 $(this).css("display", "block"); var modalHeight=$(window).height() / 2 - $("#youModel .modal-dialog").height() / 2; $(this).find(".modal-dialog").css({ "margin-top": modalHeight }); });这样就可以解决闪动问题并完美居中了。
以上就是本文的全部内容,希望对大家的学习有所帮助,也希望大家多多支持脚本之家。