【发布时间】:2020-06-20 02:43:04
【问题描述】:
我有两个或更多基于此的点击事件我想打开 Bootstrap 模式。我的问题是当我使用 jquery 和 Inside modal 打开模态时,我想考虑三个部分。在我的点击事件中,我也有三个与模态中的考虑相同。对于我要单击的实例,现在引导模式已触发(打开),但它无法获取特定部分的偏移值,并且它也无法在模式内滚动。我唯一的意图是基于单击需要滚动引导模式并显示特定部分。
这里我附上了我的引导模式代码
<div class="modal fade modal5 in" id="myModal" role="dialog">
<div class="modal-dialog">
<div class="modal-content modal-content">
<div class="modal-header">
<button type="button" class="close" data-dismiss="modal">×</button>
<h4 class="modal-title">Testing</h4>
</div>
<div class="modal5-body">
<div class="terms_condition section-1" data-section="section-1" id="section-1">
<h3>Section One</h3>
<p>Lorem Ipsum is simply dummy text of the printing and typesetting industry.</p>
<p>Lorem Ipsum is simply dummy text of the printing and typesetting industry.</p>
<p>Lorem Ipsum is simply dummy text of the printing and typesetting industry.</p>
<p>Lorem Ipsum is simply dummy text of the printing and typesetting industry.</p>
<p>Lorem Ipsum is simply dummy text of the printing and typesetting industry.</p>
<p>Lorem Ipsum is simply dummy text of the printing and typesetting industry.</p>
<p>Lorem Ipsum is simply dummy text of the printing and typesetting industry.</p>
<p>Lorem Ipsum is simply dummy text of the printing and typesetting industry.</p>
<p>Lorem Ipsum is simply dummy text of the printing and typesetting industry.</p>
<p>Lorem Ipsum is simply dummy text of the printing and typesetting industry.</p>
</div>
<div class="terms_condition section-2" data-section="section-2" id="section-2">
<h3>Section Two</h3>
<p>Lorem Ipsum is simply dummy text of the printing and typesetting industry.</p>
<p>Lorem Ipsum is simply dummy text of the printing and typesetting industry.</p>
<p>Lorem Ipsum is simply dummy text of the printing and typesetting industry.</p>
<p>Lorem Ipsum is simply dummy text of the printing and typesetting industry.</p>
<p>Lorem Ipsum is simply dummy text of the printing and typesetting industry.</p>
<p>Lorem Ipsum is simply dummy text of the printing and typesetting industry.</p>
<p>Lorem Ipsum is simply dummy text of the printing and typesetting industry.</p>
<p>Lorem Ipsum is simply dummy text of the printing and typesetting industry.</p>
<p>Lorem Ipsum is simply dummy text of the printing and typesetting industry.</p>
<p>Lorem Ipsum is simply dummy text of the printing and typesetting industry.</p>
</div>
<div class="terms_condition section-3" data-section="section-3" id="section-3">
<h3>Section Three</h3>
<p>Lorem Ipsum is simply dummy text of the printing and typesetting industry.</p>
<p>Lorem Ipsum is simply dummy text of the printing and typesetting industry.</p>
<p>Lorem Ipsum is simply dummy text of the printing and typesetting industry.</p>
<p>Lorem Ipsum is simply dummy text of the printing and typesetting industry.</p>
<p>Lorem Ipsum is simply dummy text of the printing and typesetting industry.</p>
<p>Lorem Ipsum is simply dummy text of the printing and typesetting industry.</p>
<p>Lorem Ipsum is simply dummy text of the printing and typesetting industry.</p>
<p>Lorem Ipsum is simply dummy text of the printing and typesetting industry.</p>
<p>Lorem Ipsum is simply dummy text of the printing and typesetting industry.</p>
<p>Lorem Ipsum is simply dummy text of the printing and typesetting industry.</p>
</div> </div>
<div class="modal-footer">
<button type="button" class="btn btn-default" data-dismiss="modal">Close</button>
</div>
</div>
</div>
对于我的点击事件 Html 代码
<a href="#" data-toggle="modal" data-target="#myModal5" data-section="section-1"> T & C</a>
<a href="#" data-toggle="modal" data-target="#myModal5" data-section="section-2"> T & C</a>
<a href="#" data-toggle="modal" data-target="#myModal5" data-section="section-3"> T & C</a>
我的 Jquery 应该是这样的
$(document).on('show.bs.modal', '#myModal5', function(event) {
var section = $(event.relatedTarget).data('section');
var sectionOffset = $('#' + section).offset();
$('#myModal5 .modal5-body').animate({
scrollTop: sectionOffset.top
}, 1000);
});
【问题讨论】:
标签: twitter-bootstrap scroll modal-dialog click bootstrap-modal