modal center 居中

function centerModal(modalobj){
	if(modalobj.hasClass('modal')){
		modalobj.each(function(i){
			var $clone = $(this).clone().css('display', 'block').appendTo('body');
			var top = Math.round(($clone.height() - $clone.find('.modal-content').height()) / 2);
			top = top > 0 ? top : 0;
			$clone.remove();
			$(this).find('.modal-content').css("margin-top", top);
		});
	}
}

$('.modal').on('show.bs.modal', centerModal);
$(window).on('resize', centerModal);

 

$scope.$watch('step',function(newValue,oldValue, scope){
    if(newValue == 1){
        var marginTop = (document.documentElement.clientHeight - 186) / 2;
        console.log(marginTop);
        modalobj.find('.modal-content').css('margin-top', marginTop +'px');
    } else {
        centerModal(modalobj);
    }
});

 

 

posted @ 2015-06-25 10:59  立己达人  阅读(342)  评论(0编辑  收藏  举报