模态框动画+随屏幕高度垂直居中

2018-02-09  本文已影响22人  紫灬楓
$('#modalButton,#wl-footer-rating').click(function () {
    $('#myModal').on('shown.bs.modal', function () {  //获取弹框
        // $('.modal_form input').eq(0).focus();
        var modalHeight = ($(window).height() - $('.modal-dialog').height())/2;
        $('.modal-dialog').stop().css({'margin-top':0}).animate({
            'margin-top': modalHeight
        });
        $(window).resize(function () {  //随屏幕高度垂直居中
            var modalTop = ($(window).height() - $('.modal-dialog').height())/2;
            $('.modal-dialog').css({
                'margin-top': modalTop
            });
        });
    });
});
上一篇下一篇

猜你喜欢

热点阅读