ngx-bootstrap-modal 相关问题


如何确定 Bootstrap 5 Modal 按钮不起作用的原因?

我有一个基于 Django 的网站,使用 bootstrap 5。我有一个数据表和一个包含大量文本的注释列。我正在尝试使用 Bootstrap Modal 弹出功能来显示要保留的注释...


Laravel 线元素包 - 如何将其与 bootstrap 主题一起使用?

有这个包https://github.com/wire-elements/modal。 我已按照配置步骤来实现模式,但是我使用了不同的 CSS 框架。我的问题是哪里说:


ngx-color-picker 安装出现错误

我正在尝试按照以下说明在我的 Angular 应用程序中安装 ngx-color-picker: https://www.npmjs.com/package/ngx-color-picker/v/16.0.0 使用下面的命令安装它是有效的


如果单击事件不可用,则面临使用 ngx-charts 隐藏指针的问题

从昨天开始,我一直在尝试修补泳道/ngx-charts库,以在鼠标悬停时隐藏图表中的指针。我们正在使用这个库中的饼图,这就是默认的方式


Python 包安装问题:ModuleNotFoundError

我正在尝试使用 modal-python 包。 使用 Google Colab 笔记本时,在安装 pip install modal-python 软件包后,我可以轻松地按预期使用该软件包。例如:从 modAL.models 导入


脚本无法在我的引导模式中工作

希望这不是一个愚蠢的问题,但我已经没有主意了...... 所以我有这个模式: 1.scala.html 希望这不是一个愚蠢的问题,但我已经没有主意了...... 所以我有这个模式: 1.scala.html <div class="feat" id="cor" data-toggle="tooltip" data-placement="bottom" title="add conference role"><div data-toggle="modal" data-target="#conf-role-menu-modal">Conference Role</div></div> <div class="modal fade" id="conf-role-menu-modal" tabindex="-1" role="dialog" aria-labelledby="myModalLabel" aria-hidden="true"> <div class="modal-dialog"> <div class="modal-content"> <div class="modal-header"> <button type="button" class="close" data-dismiss="modal" aria-label="Close"><span aria-hidden="true">&times;</span></button> <h4 class="modal-title" id="myModalLabel">Modal title</h4> </div> <div class="modal-body-conf-role-menu"> <script type="text/javascript"> $(function(){ $(".modal-body-conf-role-menu").load("@routes.Application.areaConferenceRole(id,idenv)"); }); </script> </div> <div class="modal-footer"> <button type="button" class="btn btn-default" data-dismiss="modal">Close</button> </div> </div> </div> </div> 使用模态主体中的脚本,我尝试加载此页面: 2.scala.html @(id:String, idenv:String) @Main("Add area") { <form action="@routes.Application.areaPostConferenceRole(id,idenv)" method="POST"> First Name: <input type="text" name="first_name" id="first" class="form-control"> Last Name : <input name="last_name" class="form-control"> <script type="text/javascript"> $( document ).ready(function() { // Handler for .ready() called. $( "#first" ).focus(function() { alert( "Handler for .focus() called." ); }); }); </script> </form> } 页面加载正常。我在我的模态中看到它...... 问题是我的页面 2.scala.html 中的脚本无法运行。我不明白为什么......如果我从我尝试在模态中加载的页面之外尝试它们,它们就会起作用...... $( document ).ready(function(){}); 永远不会在模态中到达,因为加载页面时已经触发了此事件(模态在之后加载...) 尝试直接插入脚本,如下所示: <script type="text/javascript"> $( "#first" ).focus(function() { alert( "Handler for .focus() called." ); }); </script> 当引导模式弹出时,shown.bs.modal事件将被触发。这是例子。 $('#myModal').on('shown.bs.modal', function () { $('#myInput').trigger('focus') }) Full documentation. https://getbootstrap.com/docs/4.0/components/modal/ 试试这个我已经准备好这个功能了 $('#myModal').on('shown.bs.modal', function () { // Your script here }); $(document).on('shown.bs.modal', '#myModal', function () { // Your script here });


nz-select 下拉列表不会在 nz-modal 中自行连接

在内容可滚动的 nz-modal 中使用 nz-select 时,您会看到页面滚动后下拉列表未连接到自身。 期待显示 错误显示 这是重现该问题的示例...


Expo Development 客户端 Ios 构建问题?

不变违规:requireNativeComponent:在 UIManager 中找不到“RNDateTimePicker”。 此错误显示在 "react-native-modal-datetime-picker": "^17.0.0", ...


在 Angular 中打开模态时出现ExpressionChangedAfterItHasBeenCheckedError

` `<ngx-datatable-column *ngIf="search_type ==='booking'" [width]="50" [sortable]="false" [canAutoResize]="false" [draggable]="false" [resizeable]="false"> <ng-template ngx-datatable-cell-template let-row="row" let-value="value"> <span class="fa fa-user-plus font-medium-3 text-primary cursor-pointer pl-1" (click)="onUpdateBookingLinguist(row)"></span> </ng-template> </ngx-datatable-column>` 上面是我的html代码,下面是我的ts代码 ` onUpdateBookingLinguist(linguist: Linguist) { const modalRef = this.modalService.open(ScheduledBookingModalComponent, { size: 'lg' }); modalRef.componentInstance.linguist_other_bookings = linguist['scheduled_booking']; modalRef.result.then((result) => { if (!result) { return; } this.cdr.detectChanges(); }).catch((e) => { }); this.cdr.detectChanges(); }` 我试图从 ngx-datatable-column 打开模式,但收到此错误 错误错误:NG0100:ExpressionChangedAfterItHasBeenCheckedError:表达式在检查后已更改。上一个值:“datatable-body-cell sort-active active”。当前值:'datatable-body-cell sort-active'.. 欲了解更多信息,请访问 https://angular.io/errors/NG0100 我尝试使用 ChangeDetectorRef.detectChanges() 手动触发更改检测,但仍然收到错误。 当您修改 Angular 在其更改检测周期期间也尝试检查或更新的属性时,通常会出现此错误。 因此您可以使用 ChangeDetectorRef 在特定情况下手动触发更改检测。通过从 ChangeDetectorRef 调用 detectorChanges(),您可以手动指示 Angular 对该组件及其子组件重新运行更改检测,从而可能解决问题 这是如何在组件中使用ChangeDetectorRef 的示例 构造函数(私有 cdr:ChangeDetectorRef){} ngAfterContentChecked() { this.cdr.detectChanges(); }


Bootstrap 5.2 下拉菜单在 Laravel 中不起作用

我已经从 Bootstrap 网站安装了预配置的导航栏之一。是Bootstrap 5.2的最新版本;但是,下拉菜单不起作用。我没有碰代码;这只是一个定义...


在 Rails 7 应用程序中使用 bootstrap javascript

我有一个正在运行的 Rails 7 应用程序,它使用 esbuild 作为 JS 捆绑器并导入了 bootstrap。 我正在尝试弄清楚如何访问主“外部”的任何 Bootstrap Javascript 功能


如何在 Rails 7 esbuild 应用程序中显示 Bootstrap 5.3 弹出窗口?

当我使用 Bootstrap 创建全新的 Rails 7 应用程序时,Modals 可以开箱即用,但 Popover 则不然。我如何让他们工作? Rails 7.1.2、esbuild、Bootstrap 5.3.2: Rails 新 -- 数据库 sqlite3 --


应用程序定制器和多个Web部件中的jquery和bootstrap

是个人选择使用bootstrap进行定制。因此,我计划在应用程序定制器和多个 Web 部件中使用 jQuery 和 Bootstrap。对此最好的方法是什么?我正在尝试...


链接点击时的反应模式调用

使用react-modal,我需要通过锚标记或react-router-dom链接单击超链接时显示模式。 示例:单击注册超链接,注册表模式应打开。


PHP 与 Bootstrap 轮播

我正在尝试学习 PHP 并将其与我的网站的 Bootstrap 库一起使用。我希望使用引导程序轮播,如此处所示 我想要实现的是带有标题的轮播和


从 Material UI Modal 中删除边框

我正在尝试使用 React Material UI 模态,但当它聚焦时,我总是在模态周围看到黑色边框。当它失焦时我已经删除了边框,但是如果模态聚焦......


带有 --css bootstrap 的 Rails 7 新应用程序 - Turbo 按钮不起作用

使用 Rails new myapp --css bootstrap 创建新应用程序 Rails 7 时,我的涡轮按钮将不起作用: =button_to“退出”,edit_post_path,方法::删除,形式:{数据:{turbo_confirm:“...


为什么我们不能使用CSS改变Bootstrap 4中徽章类的颜色?

Bootstrap v4.3.1 中徽章的类是 。徽章 { 显示:内联块; 填充:0.25em 0.4em; 字体大小:75%; 字体粗细:700; 行高:1; 文本对齐:居中; 白色-s...


Bootstrap 模式仅显示 MongoDB 集合中的第一条记录

我正在使用 NodeJS、Handlebars 和 Bootstrap 构建一个简单的 Web 应用程序。它应该循环遍历模拟产品的 MongoDB 集合并显示其字段。 我正在“产品...


React Native:模态问题 - 按下按钮时模态未关闭

我目前在 React Native 项目中遇到与 Modal 组件相关的问题。尽管设置了一个按钮来关闭模式,但它并没有按预期工作。这是...的简化版本...


Bootstrap 5使用js切换折叠不起作用

出于某种原因,我想在没有ID的情况下使用折叠。我在 stackoverflow 上找到了一个旧答案,它似乎在 Bootstrap 5 中不起作用。 错误:未捕获类型错误:c.nextElementSibling.collapse i...


Bootstrap 无法与 Rails 正确配合使用

大家好 我使用这个入门模板启动一个新的 Rails 应用程序,当我从 bootstrap 添加一个简单的导航栏时。 它看起来像这样 主要问题是JS不起作用,下拉菜单我...


如何在没有ID的情况下初始化和操作Bootstrap Collapse?

出于某种原因,我想在没有ID的情况下使用折叠。我在 stackoverflow 上找到了一个旧答案,它似乎在 Bootstrap 5 中不起作用。 错误:未捕获类型错误:c.nextElementSibling.collapse i...


Bootstrap CSS - 将页面从中心向下拆分。用图像填充左侧,用文本填充右侧

我对 bootstrap 5 相当熟悉,但我正在开发一个项目,我试图找出将页面从中心拆分的最佳方法,但中间还有一个容器,允许.. .


如何用html和bootstrap保证屏幕宽度内自动换行

我正在 Flask、Mongodb、HTML 和 Bootstrap 上制作一个 Web 应用程序。我的问题是表格列中的单词会从屏幕上消失,我需要滚动浏览器窗口才能阅读它们。 可以请你...


我如何根据状态更改按钮颜色(绿色表示“接受”,红色表示“删除”)

如何根据状态更改按钮颜色(绿色表示“接受”,红色表示“删除”) 我是新人,为此使用 Laravel 框架。 这是我的观点 如何根据状态更改按钮颜色(绿色表示“接受”,红色表示“删除”) 我是新人,为此使用 Laravel 框架。 这是我的看法 <table class="table table-striped" id="example"> <thead> <tr> <th>ID no</th> <th>Form Name</th> <th style="text-align: center">Update</th> <th>Delete</th> <th>Status</th> </tr> </thead> @foreach($form as $show) {{--modal--}} <div class="modal fade mj_popupdesign mj_checkoutpopup" id="myModal2" tabindex="-1" role="dialog" aria-labelledby="myModalLabel"> <div class="modal-dialog" role="document"> <div class="modal-content"> <div class="modal-body"> <div class="col-lg-8 col-md-8 col-sm-12 col-xs-12 col-lg-offset-2 col-md-offset-2"> <div class="row"> <div class="mj_pricingtable mj_greentable mj_login_form_wrapper"> <form> <div class="mj_login_form"> <p>Are you sure you want to delete this post?</p> <br> <a href="" class="mj_btn btn btn-default pull-right glyphicon glyphicon-remove "> No</a> <a href="{{url('deleteForm',$show->id)}}" class=" pull-right mj_btn btn btn-danger glyphicon glyphicon-ok"> Yes</a> </div> </form> </div> </div> </div> </div> </div> </div> </div> {{--end modal--}} <tbody> <tr> <td> <p> {{$show->id}}</p> </td> <td> <h6><a href="{{url('JobDetails',$show->id)}}"style="color: rgb(0, 191, 243);font-size:18px;float: left;margin: 0;text-align: left">{{$show->jobTitle}}</a> </h6> <p> {{$show->created_at}} </p> </td> <td> <a href="{{url('UpdateFormView',$show->id)}}"> <span class="mj_btn btn btn-success">Update</span> </a> </td> <td> <span class="mj_btn btn btn-danger" data-toggle="modal" data-target="#myModal2">Delete</span> </td> <td><span class="mj_btn btn btn-warning">pending</span> </td> </tr> </tbody> @endforeach </table> </div> </div> </div> </div> 在我的控制器中public function AcquiredForm() { $acquired="Requirement Form"; $acquireForm=Job::where('jobType','LIKE','%'.$acquired.'%'); $form = $acquireForm->get(); return view('private-pages.company.aquire-form',compact('form')); } 数据库状态默认为待处理 数据库状态默认为pending 我在代码中没有看到 status 属性,但显示状态为待处理的纯字符串 <span class="mj_btn btn btn-warning">pending</span> <!-- while it suppose to be --> <span class="mj_btn btn btn-warning">{{ $show->status }}</span> 假设它确实存在,你可以做 <td> @if ($show->status === 'Accept') <span class="mj_btn btn btn-green">Accepted</span> @elseif ($show->status === 'Delete') <span class="mj_btn btn btn-danger">Deleted</span> @else <span class="mj_btn btn btn-warning">Pending</span> @endif </td> 参见:https://laravel.com/docs/5.1/blade#displaying-data <td> @if ($show->jobstatus === "Accepted") <span class="mj_btn btn btn-success">Accepted</span> @elseif ($show->jobstatus === "Rejected") <span class="mj_btn btn btn-danger">Rejected</span> @else <span class="mj_btn btn btn-warning">Pending</span> @endif </td> 或者当你使用 1. laravel esialy customaize this code nad add automatic refresh in the page to more interactive @php if($da->status == "requested") { echo "<td><button class='btn btn-primary'>Requested</button></td>"; } else { echo "<td><button class='btn btn-success'>Ordered</button></td>"; } @endphp


如何让 Reactstrap 响应式?

我刚开始使用reactstrap(不是react-bootstrap),并且正在尝试如何渲染“移动”和“桌面”视图。 我如何让reactstrap渲染页面...


Alpine.js 和 jQuery DataTables,x-on:在表内触发时单击功能不全

我的 Laravel 和 Alpine.js 刀片页面中有此表。 名字 我的 Laravel 和 Alpine.js 刀片页面中有此表。 <table id="projects-table"> <thead> <tr> <th>name</th> <th>actions</th> </tr> </thead> <tbody> @foreach($projects as $project) <tr> <td>{{ $project->name }}</td> <td><button x-data="{}" x-on:click="$dispatch('open-modal', 'edit-project')">edit</button></td> </tr> @endforeach </tbody> </table> 有了它,我有了这个 JavaScript 代码,可以将其转换为 jQuery DataTable document.addEventListener('DOMContentLoaded', function () { new DataTable('#projects-table'); }); 现在发生的情况是,当我单击 button 内的 td 时,我的模式不会触发 当表不是 DataTable 时,一切正常。 基本上发生了什么(可能),当 jQuery 操作元素时,@click 事件不会触发。有任何已知的修复方法吗?感谢所有帮助。 解决方案是将表包含在由 Alpine 控制的标签中,并在 Alpine 启动后初始化 DataTable: <div x-data> <table id="projects-table"> <!-- ..... --> </table> </div> <script> document.addEventListener('alpine:init', () => { new DataTable('#projects-table') }); </script> 通过这种方式,Alpine 可以检测到 DOM 何时被 DataTables 更改,然后重建他的引用。 否则,在您的具体情况下,您可以使用 vanilla JS 发送自定义事件并保持其他内容不变: <!-- ..... --> <td> <button onclick="window.dispatchEvent(new CustomEvent('open-modal', { detail: 'edit-project' }))"> Edit </button> </td> <!-- ..... --> <!-- Simple example for the modal triggering --> <div x-data="{isOpen: false}" x-show="isOpen" @open-modal.window="isOpen = true"> I'm open! <div>


引导日期时间选择器无法运行

我正在尝试优秀的 Bootstrap DateTimePicker 插件,但似乎一开始就遇到了缓冲区。页面控件显示正确,但日历按钮完全


如何在 ASP.NET MVC 4 中为 CSP 使用动态随机数

我在 ASP.NET MVC 4 中开发了 MVC 应用程序。我在几个页面中使用了 javascript。一些 javascript 被引用为 @Scripts.Render(“~/Scripts/bootstrap”) @Scripts.Render("~/Sc...


在添加新行时刷新 html 可编辑表格 - Bootstable

我使用 boostable 插件在运行时内联编辑 HTML 行。该插件位于 https://www.jqueryscript.net/table/Editable-Tables-jQuery-Bootstrap-Bootstable.html。问题是现在当我想要的时候


如何在 Laravel 中添加外部 scss 文件?

我从Colorlib购买了一个主题,Bootstrap Sidebar V02,包含SCSS文件。将这个外部 SCSS 文件添加到 Laravel 项目的相关方法是什么? mix.sass('资源/sass/样式。


如何配置验证以对无效输入使用“is-invalid”类

默认情况下,ASP.NET Core 中的输入验证使用类 input-validation-error,但 Bootstrap 5 使用 is-invalid。 我找到了一些解决方案: 创建样式 使用 jQuery.validate.unobtrusi...


Blazor 内联渲染怪异

我正在使用 Blazor Bootstrap 并尝试在提交表单后更新页面。该表单只是创建一个数据库条目并返回 true 或 false。该页面正在使用禁用的选项卡...


BS 导航栏不适用于下载的 Bootstrap 库。 CDN 没问题,请帮助我

我正在尝试使用带有下载的库/离线的引导程序。 然而,编写的 html 与 CDN 配合得很好。 这是文件夹架构。 ...


Bootstrap 手风琴边框顶部不是第一项

我在 Angular 应用程序中使用引导手风琴,我希望周围的每个人都有一个带颜色的边框。通过标准引导程序,如果手风琴不是...


Angular 中的 JavaScript 函数“未定义”错误

我正在尝试让 Angular 17 项目正常运行。我正在使用 Bootstrap (5),并尝试让 datePicker 工作。这需要一些 JavaScript 代码,但我无法使用这些代码。我已经关注了...


当需要删除浮动标签效果时也删除

有没有一种方法可以用于 bootstrap 4 上的浮动标签,当我删除输入上所需的标签时,标签保留在边框的顶部。 $(文档).ready(函数() { $('.form-g...


鼠标悬停时停止 setTimeout 引导模式

我使用 Bootstrap 4 创建模态,并在后端添加 settimeout 以在 X 秒后关闭模态。 但如果用户没有读完该模式,这就是我的主要目标:我想停止设置...


引导模式在单击按钮时不显示内容(Django 框架)

我在 HTML 代码中遇到了 Bootstrap 模式的问题,当我单击触发它们的按钮时,它们没有显示任何内容。尽管 ID 和属性看似正确,但


Bootstrap - 如何创建具有可滚动列的全屏布局?

我正在尝试创建一个全屏布局,占据 100% 的视口,并带有粘性页眉和页脚,以及主内容区域中可单独滚动的列。 我已经和你一起实验过...


Bootstrap 5:使输入文件与其他字段具有相同的高度

我正在使用这个简单的模板来显示带有文件附件字段的注册表单: /* 当我尝试修改自己的高度时,问题就出现了 */ .mycustom{ 行高:2.75; z...


从中心向下拆分页面。用图像填充左侧,用文本填充右侧

我对 bootstrap 5 相当熟悉,但我正在开发一个项目,我试图找出将页面从中心拆分的最佳方法,但中间还有一个允许的容器。 ..


如何在 Bootstrap 5 中保持一项手风琴项目始终打开?

我默认打开了第一个手风琴项目,所以我想做的就是随时至少打开一个(因此侧面的图片保持合适的纵横比)。默认情况下我可以


在 Angular 和 Bootstrap 中,当鼠标悬停在导航项上时,如何单击展开的下拉列表中的按钮?

当前行为:将鼠标悬停在导航项上时,下拉容器变得可见,但无法单击容器内的按钮。 预期行为:悬停在...上时


如何在flex-grow容器中创建响应式表格而不影响整体布局?

我正在使用 Bootstrap 5.3 开发响应式布局,其中包括导航栏、侧栏、内容面板和状态栏。该应用程序应始终为 100% 视图高度和视图宽度,并包含所有信息...


下拉按钮在 Bootstrap 5.3 上不起作用

我正在使用 Express、EJS 和 bootstrap 制作一个网站,但下拉按钮不起作用 代码: <%- include('../includes/head') %> 我正在使用 Express、EJS 和 bootstrap 制作一个网站,但下拉按钮不起作用 代码: <%- include('../includes/head') %> <div class="dropdown"> <button class="btn btn-secondary dropdown-toggle" type="button" id="dropdownMenuButton1" data-bs-toggle="dropdown" aria-expanded="false">Dropdown button</button> <ul class="dropdown-menu" aria-labelledby="dropdownMenuButton1"> <li><a class="dropdown-item" href="#">Action</a></li> <li><a class="dropdown-item" href="#">Another action</a></li> <li><a class="dropdown-item" href="#">Something else here</a></li> </ul> </div> <%- include('../includes/footer') %> 头: <!doctype html> <html lang="en"> <head> <meta charset="utf-8"> <meta name="viewport" content="width=device-width, initial-scale=1"> <link href="https://cdn.jsdelivr.net/npm/[email protected]/dist/css/bootstrap.min.css" rel="stylesheet" integrity="sha384-T3c6CoIi6uLrA9TneNEoa7RxnatzjcDSCmG1MXxSR1GAsXEV/Dwwykc2MPK8M2HN" crossorigin="anonymous"> <title>Title</title> </head> <body> 页脚: <script src="https://cdn.jsdelivr.net/npm/[email protected]/dist/js/bootstrap.bundle.min.js" integrity="sha384-C6RzsynM9kWDrMNeT87bh95OGNyZPhcTNXj1NW7RuBCsyN/o0jlpcV8Qyq46cDfL" crossorigin="anonymous"></script> </body> </html> 当我单击按钮时,它不显示下拉菜单的内容 我不知道这是否重要/有效,但尝试将引导脚本从页脚移动到页眉,它可能基于加载顺序。


在 Angular 17 独立模式下,如何使用 Swiper 版本 11.0.5 使 Bootstrap 下拉列表在 Swiper 元素外部可见

在下面的刷卡器代码中,如何使引导下拉列表在刷卡器容器外部可见。我不想自动调整滑动器容器的高度。我希望我的容器有固定的高度......


如何在我的 Blazor 服务器 razor 页面中使用 JavaScript;提交表单时更改 blazor bootstrap 按钮的样式

我的项目是 Blazor 服务器应用程序。我想要实现的功能是,如果我的验证失败(如果我的输入中没有任何内容),我希望我的手风琴标题更改为红色......


ng-bootstrap 滚动间谍在没有高度的情况下无法工作?

我在我的项目中使用 ng-bootstrap [ngbScrollSpy] 指令,如文档中所述,但它不起作用 - 滚动时活动项目不会改变。 我的代码如下: 我在我的项目中使用 ng-bootstrap [ngbScrollSpy] 指令,如文档中所述,但它不起作用 - 滚动时活动项目不会改变。 我的代码如下: <div> <div class="sticky-top"> <ul class="nav menu-sidebar"> <li > <a [ngbScrollSpyItem]="[spy, 'about']">About</a> </li> <li > <a [ngbScrollSpyItem]="spy" fragment="schedule">Schedule</a> </li> <li > <a [ngbScrollSpyItem]="spy" fragment="hotel">Information about the hotel</a> </li> </ul> </div> <div ngbScrollSpy #spy="ngbScrollSpy" > <section ngbScrollSpyFragment="about"> <h3>About</h3> <p>{{some long long text and content}}</p> </section> <section ngbScrollSpyFragment="schedule"> <h3>Schedule</h3> <p>{{some long long text and content}}</p> </section> <section ngbScrollSpyFragment="hotel"> <h3>Information about the hotel</h3> <p>{{some long long text and content}}</p> </section> </div> </div> 我在这个 stackoverflow 问题中看到,我的问题是我没有向我的 div 提供 height,这是事实。 但我的滚动间谍部分遍布整个页面,而不是一个小 div,(导航本身是 sticky-top)。所以我不能给它高度。 我知道有替代方法 - 刷新窗口滚动上的滚动间谍,但我没有找到可以帮助我的正确代码。 你能解决我的问题吗? 为我提供刷新滚动间谍的代码/给我有关高度的提示/帮助我找到另一个相应的元素。 非常感谢! 附上 stackblitz 演示的链接 注意:我使用来自 @ng-bootstrap/ng-bootstrap 的 NgbScrollSpy (我想它是非常相似的库) 我做什么: 我将所有内容(包括导航)包装在中 <div class="wrapper" ngbScrollSpy #spy="ngbScrollSpy" rootMargin="2px" [threshold]="1.0" > <div class="sticky-top pt-4 pb-4 bg-white"> ..here the navigation... </div> ..here the sections... <section ngbScrollSpyFragment="about"> </section> //the last I use margin-bottom:2rem; <section ngbScrollSpyFragment="hotel" style="margin-bottom:10rem" </section> </div> 见“门槛”。这表明“更改”活动片段应该可见的百分比(1 是 100%) 包装类 .wrapper{ height:100%; position: absolute; top:0; } 我使用强制链接的类别 //remove all the class for the link a{ color:black; text-decoration:none; padding:8px 16px; } a.custom-active{ color:white; background-color:royalblue } 以及我使用的每个链接 <a [class.custom-active]="spy.active=='about'">About</a> 嗯,问题是如何“滚动到”。 “链接”应该作为链接使用。 第一个是指示“路由器”应该考虑“碎片” 如果我们的组件是独立组件,我们需要使用提供者,provideRouter bootstrapApplication(App, { providers: [ provideRouter([], withInMemoryScrolling({anchorScrolling:'enabled'})), ] }) 然后,我们需要考虑到我们的页面确实没有滚动,div“包装器”是谁拥有滚动。因此,我们订阅 router.events,当事件有“锚点”时,我们滚动“包装器”div constructor(router: Router) { router.events.pipe(filter((e:any) => e.anchor)).subscribe((e: any) => { (document.getElementById('wrapper') as any).scrollTop+= (document.getElementById(e.anchor)?.getBoundingClientRect().top||0) -72; //<--this is the offset }); } 在这个stactblitz中你有一个有效的例子


© www.soinside.com 2019 - 2024. All rights reserved.