javascript - Bug Bootstrap 4 和 fullcalendar.js - bootstrap 4 模式中的 fullcalendar

标签 javascript css bootstrap-4 fullcalendar

我将 fullcalendar.js 与 Bootstrap 4 模态一起使用。

当我点击它时,我有一个 bootstrap4 按钮,一个带有 fullcalendar 组件的模态显示。

但是当它第一次加载时我得到这个:

enter image description here

但是当我点击按钮时,下一个/上一个按钮工作正常

enter image description here

那么我该如何解决。

HTML代码

<body>

        <div id="content">

            <button id="btn-calendar" type="button" class="btn btn-dark" data-toggle="modal" data-target="#modal-calendar"><i class="fas fa-calendar-alt"></i></button>

            <div class="modal fade" id="modal-calendar" tabindex="-1" role="dialog" aria-labelledby="modal-calendar-title" aria-hidden="true">
                <div class="modal-dialog modal-dialog-centered" role="document">
                    <div class="modal-content">
                        <div class="modal-header">
                            <h5 class="modal-title" id="modal-calendar-title">Calendar</h5>
                            <button type="button" class="close" data-dismiss="modal" aria-label="Close">
                                <span aria-hidden="true">&times;</span>
                            </button>
                        </div>
                        <div class="modal-body">
                            <div id="calendar"></div>
                        </div>
                        <div class="modal-footer">
                            <button type="button" class="btn btn-secondary" data-dismiss="modal">Close</button>
                            <button type="button" class="btn btn-primary">Save changes</button>
                        </div>
                    </div>
                </div>
            </div>

        </div>
        <!-- script tags -->
</body>

CSS 代码:

* {
  margin: 0;
  padding: 0;
}

html,
body,
#content {
  width: 100%;
  height: 100%;
}

#btn-calendar {
  margin: 10px;
}

最佳答案

如果我在第一次打开模式后创建对象,它会起作用。

//应用程序.js

$(function() {
    var render = () => {
        console.log('render after modal is open');   
        $('#calendar').fullCalendar({
            // setup
        })
        $('.modal').unbind('shown.bs.modal', render)
    }
    $('.modal').on('shown.bs.modal', render)
})

关于javascript - Bug Bootstrap 4 和 fullcalendar.js - bootstrap 4 模式中的 fullcalendar,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/55088721/

相关文章:

javascript - 在 Safari 中,下拉选项位于顶部

CSS [DIV-Tableless] 垂直堆叠不同高度填补空白?

包含 5 个具有相同类名的 ul 的无序列表的 css 样式,对每个应用不同的样式

css - Bootstrap 4 卡/面板,带有标题和标题左侧的图像

javascript - 如何获得网页中某个操作的确认?

javascript - jQuery JSON API 调用不起作用?

html - 如何在兄弟 div 留下的剩余空间中居中 div

html - 某些 Bootstrap 4 类在我的 Angular 8 元素中不起作用

css - bootstrap 4 中心标题和右对齐按钮全部在一排

javascript - 用下格定位上格