jQuery使用抽屉使div在右侧弹出,再点击任意处关闭,附angularjs模态框实现

HTML

<div class="ms-auto">
    <div class="btn-group">
        <!-- 1.抽屉 --> 
        <button id="drawerButton" ng-click="getLogs();openDrawer()">
             Log
        </button>
        <!-- 2.Modal 模态框--> 
        <button ng-click="getLogs();" data-bs-target="#logModal" data-bs-toggle="modal">
             Log
        </button>
    </div>
</div>

<div id="drawer" ng-show="showDrawer" ng-style="getDrawerStyle()">
    <div class="table-responsive row">
        <table class="table">
            <thead class="header-item">
                <th style="width: 20%">Time</th>
                <th style="width: 20%">Name</th>
                <th style="width: 30%">Action</th>
                <th style="width: 30%">Object</th>
            </thead>

            <tbody>
                <!-- start row -->
                <tr></tr>
                <!-- end row -->
            </tbody>
        </table>
    </div>
</div>

<div class="modal fade" id="logModal" role="dialog" data-bs-backdrop="static">
    <div class="modal-dialog modal-lg">
        <div class="modal-content">
            <div class="modal-header modal-colored-header bg-primary text-white">
                <h4 class="modal-title">Operation Log</h4>
                <button type="button" class="btn-close" data-bs-dismiss="modal"
                        aria-label="Close"></button>
            </div>
            <div class="modal-body">
                <div class="table-responsive row">
                    <table class="table">
                        <thead class="header-item">
                            <th style="width: 20%">Time</th>
                            <th style="width: 20%">Name</th>
                            <th style="width: 30%">Action</th>
                            <th style="width: 30%">Object</th>
                        </thead>

                        <tbody>
                            <!-- start row -->
                                <tr></tr>
                            <!-- end row -->
                        </tbody>
                    </table>
                </div>
            </div>
            <div class="modal-footer">
                <button class="btn btn-dark" type="button" data-bs-dismiss="modal">Close</button>
            </div>
        </div>
    </div>
</div>

控制器js

$scope.getLogs = function () {
    $http({
        method: 'GET',
        url: '/api/v1/' + $scope.modules.snake + '/logs?pagenumber=1&pagesize=9999',
    }).then(function successCallback(response) {
        $scope.logList = response.data.resultSet;
    }, function errorCallback() {
        console.log('error');
    }).finally(function () {
    });
}

$scope.showDrawer = false;
    $scope.getDrawerStyle = function () {
        return {
            'position': 'fixed',
            'top': '0',
            'right': '-600px',
            'width': '600px',
            'height': '100%',
            'background-color': '#e2e2ff',
            'padding': '20px',
            'transition': 'right 0.4s ease',
            'z-index': '9999',
        }
    }

    $scope.openDrawer = function () {
        $scope.showDrawer = true;
        let $drawer = $("#drawer");
        $drawer.css("right", "0");
        $drawer.css("top", "65px");
    }

    // Click anywhere on the page to close the drawer
    $(document).on("click", function (event) {
        let $drawer = $("#drawer");
        if ($scope.showDrawer && !$(event.target).closest("#drawer").length && !$(event.target).closest("#drawerButton").length) {
            $scope.showDrawer = false;
            $drawer.css("right", "-600px");
        }
    });

特此记录。

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值