Angularjs ui bootstrap:如何垂直中心模态组件?

前端之家收集整理的这篇文章主要介绍了Angularjs ui bootstrap:如何垂直中心模态组件?前端之家小编觉得挺不错的,现在分享给大家,也给大家做个参考。
最近我正在学习angularjs.我以前用过bootstrap.使用jquery,我可以轻松更改模态组件位置的位置,使其垂直对齐.现在有了angularjs,这似乎并不容易.这是一个ui bootstrap模式的plunker链接,有谁知道如何使它垂直对齐?

ui bootstrap modal component

1.index.html

<!doctype html>
    <html ng-app="ui.bootstrap.demo">
    <head>
        <script src="//ajax.googleapis.com/ajax/libs/angularjs/1.5.0/angular.js"></script>
        <script src="//ajax.googleapis.com/ajax/libs/angularjs/1.5.0/angular-animate.js"></script>
        <script src="//angular-ui.github.io/bootstrap/ui-bootstrap-tpls-1.2.1.js"></script>
        <script src="example.js"></script>
        <link href="//netdna.bootstrapcdn.com/bootstrap/3.3.6/css/bootstrap.min.css" rel="stylesheet">
    </head>
    <body>
        <div ng-controller="ModalDemoCtrl">
            <script type="text/ng-template" id="myModalContent.html">
                <div class="modal-header">
                    <h3 class="modal-title">I'm a modal!</h3>
                </div>
                <div class="modal-body">
                    This is modal body
                </div>
                <div class="modal-footer">
                    <button class="btn btn-primary" type="button" ng-click="ok()">OK</button>
                    <button class="btn btn-warning" type="button" ng-click="cancel()">Cancel</button>
                </div>
            </script>
            <button type="button" class="btn btn-default" ng-click="open()">Open me!</button>
        </div>
    </body>
</html>

2.example.js

angular.module('ui.bootstrap.demo',['ngAnimate','ui.bootstrap']);
    angular.module('ui.bootstrap.demo').controller('ModalDemoCtrl',function($scope,$uibModal,$log) {

        $scope.items = ['item1','item2','item3'];

        $scope.animationsEnabled = true;

        $scope.open = function(size) {

            var modalInstance = $uibModal.open({
                animation: $scope.animationsEnabled,templateUrl: 'myModalContent.html',controller: 'ModalInstanceCtrl',size: size,resolve: {
                    items: function() {
                        return $scope.items;
                    }
                }
            });
        };
    });

    angular.module('ui.bootstrap.demo').controller('ModalInstanceCtrl',$uibModalInstance,items) {
        $scope.ok = function() {
            $uibModalInstance.close($scope.selected.item);
        };

        $scope.cancel = function() {
            $uibModalInstance.dismiss('cancel');
        };
    });
如果我正确理解您的问题,您只需使用CSS即可实现垂直中心对齐.添加以下CSS:
.modal {
  text-align: center;
  padding: 0!important;
}

.modal::before {
  content: '';
  display: inline-block;
  height: 100%;
  vertical-align: middle;
  margin-right: -4px;
}

.modal-dialog {
  display: inline-block;
  text-align: left;
  vertical-align: middle;
}

我已经设置了一个从您的分叉的Plunker来进行演示.

您可以找到以下链接

> Bootstrap 3 modal vertical position center
> @L_404_3@

希望这可以帮助.干杯!!

原文链接:https://www.f2er.com/angularjs/143681.html

猜你在找的Angularjs相关文章