我想强制用户阅读模式内的所有协议。这个想法很简单,如果他们不滚动到文本的最后一行。该按钮仍然禁用。但该按钮未启用。这是我的代码:
JavaScript:
$('#agreement').scroll(function () {
if ($(this).scrollTop() == $(this)[0].scrollHeight - $(this).height()) {
$('#closeBtn').removeAttr('disabled');
}
});
至于更清晰的图片。我把代码放到了js这里:http://jsfiddle.net/h3WDq/1129/ http://jsfiddle.net/h3WDq/1129/
这是@BG101 的更新版本。当我滚动到底部时,该按钮启用,但即使再次单击模式按钮,它仍然保持启用状态。http://jsfiddle.net/h3WDq/1132/ http://jsfiddle.net/h3WDq/1132/
your modal-body
需要滚动事件,并且您需要对if
:-
$('.modal-body').scroll(function () {
if ($('#agreement').height() == ($(this).scrollTop() + $(this).height())) {
$('#closeBtn').removeAttr('disabled');
}
});
下面的工作片段(更新为打开/关闭)
$('.modal-body').scroll(function() {
var disable = $('#agreement').height() != ($(this).scrollTop() + $(this).height());
$('#closeBtn').prop('disabled', disable);
});
.btn-group {
z-index: 1051;
}
.modal-body {
height: 300px;
overflow: auto
}
<link href="http://cdnjs.cloudflare.com/ajax/libs/twitter-bootstrap/2.3.1/css/bootstrap.css" rel="stylesheet" />
<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script>
<script src="http://cdnjs.cloudflare.com/ajax/libs/twitter-bootstrap/2.3.1/js/bootstrap.min.js"></script>
<div class="container">
<h3>User Agreement</h3>
<!-- Button to trigger modal -->
<div>
<a href="#myModal1" role="button" class="btn" data-toggle="modal">Launch Modal</a>
</div>
<!-- Modal -->
<div id="myModal1" class="modal hide" tabindex="-1" role="dialog">
<div class="modal-header">
<button type="button" class="close" data-dismiss="modal" aria-hidden="true">×</button>
<h3>User Agreement</h3>
</div>
<div class="modal-body">
<div id="agreement" style="height:1000px;">
A very long agreement
</div>
</div>
<div class="modal-footer">
<button id="closeBtn" class="btn btn-primary" data-dismiss="modal" aria-hidden="true" disabled>I Accept</button>
</div>
</div>
</div>
本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)