首页
学习
活动
专区
圈层
工具
发布
首页
学习
活动
专区
圈层
工具
MCP广场
社区首页 >问答首页 >Angularjs ui引导:如何垂直中心模态组件?

Angularjs ui引导:如何垂直中心模态组件?
EN

Stack Overflow用户
提问于 2016-02-29 06:29:14
回答 4查看 24.6K关注 0票数 13

最近我在学天使语。我以前用过鞋带。使用jquery,我可以轻松地更改模态组件位置的位置,使其垂直对齐。现在使用angularjs,这似乎不太容易做到。下面是ui引导模式的柱塞链接,有人知道如何使其垂直对齐吗?

ui自举模态元件

1.index.html

代码语言:javascript
运行
复制
    <!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

代码语言:javascript
运行
复制
    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',   function($scope, $uibModalInstance, items) {
        $scope.ok = function() {
            $uibModalInstance.close($scope.selected.item);
        };

        $scope.cancel = function() {
            $uibModalInstance.dismiss('cancel');
        };
    });
EN

回答 4

Stack Overflow用户

回答已采纳

发布于 2016-02-29 06:46:03

如果我正确理解了您的问题,您可以使用CSS实现垂直中心对齐。添加以下CSS:

代码语言:javascript
运行
复制
.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;
}

我已经设置了一个柱塞叉从你的做一个示范。

您可以发现以下链接很有帮助

  1. 自举3模态垂直位置中心
  2. 柯丁枫树

希望这能有所帮助。干杯!!

票数 26
EN

Stack Overflow用户

发布于 2018-02-28 08:39:35

上述解决方案将适用于所有的模式。如果您想应用于选择性调制解调器,那么遵循以下给定的解决方案。

CSS使用.class-a.class-b.class-a .class-b选择器,需要设置选项windowClass

代码语言:javascript
运行
复制
.center-modal.modal {
  text-align: center;
}

@media screen and (min-width: 768px) { 
  .center-modal.modal:before {
    display: inline-block;
    vertical-align: middle;
    content: " ";
    height: 100%;
  }
}

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

var modalInstance = $uibModal.open({
    templateUrl: 'modules/users/client/views/authentication/login.client.view.html',
    windowClass: "center-modal"
});
票数 2
EN

Stack Overflow用户

发布于 2019-05-22 14:18:15

可以在windowTopClass方法的对象参数中使用open属性。

https://angular-ui.github.io/bootstrap/

代码语言:javascript
运行
复制
$uibModal.open({
  ...
  ...
  windowTopClass: "modal-center-override"
});

使用相应的CSS类重写。

代码语言:javascript
运行
复制
.modal-center-override {
  top: 50% !important;
  transform: translateY(-50%) !important;
  -webkit-transform: translateY(-50%) !important;
  -moz-transform: translateY(-50%) !important;
  -o-transform: translateY(-50%) !important;  
}
票数 1
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/35693218

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档