小编Adi*_*eld的帖子

JQuery滚动到Bootstrap Modal的顶部

我目前正在使用bootstrap模式插件在我正在设计的网站上显示长法律消息,但问题是如果你打开另一个模态后,第二个将已经滚动到第一个模块的任何位置.所以我正在寻找一种使用JS/JQuery将div滚动到顶部的方法.这是我目前使用的代码:

HTML:

<!--MODAL-->
<div id="modal" class="modal hide fade" tabindex="-1" role="dialog" aria-labelledby="modalTitle" aria-hidden="true">
<div class="modal-header">
<button type="button" class="close" data-dismiss="modal" aria-hidden="true">×</button>
<h3 id="modalTitle"></h3>
</div>
<div id="modal-content" class="modal-body">
</div>
<div class="modal-footer">
<button id="modalPrint" class="btn btn-info hidden-phone" onClick=''>Print</button>
<button class="btn" data-dismiss="modal" aria-hidden="true">Close</button>
</div>
</div>
Run Code Online (Sandbox Code Playgroud)

使用Javascript:

function openModal(heading, url) {
    $.ajax({
    url: url,
    cache: false
    }).done(function( html ) {
    $("#modal-content").html(html);
    $("#modalTitle").html(heading);
    $('#modalPrint').attr('onClick', 'loadPrintDocument(printCookies, {attr : "href", url : '+ url +', showMessage: false, message: "Please wait while we create your document"})');
    $('#modal').modal('show');
    $("#modal-content").scrollTop(0);
    });
} …
Run Code Online (Sandbox Code Playgroud)

javascript jquery twitter-bootstrap

47
推荐指数
4
解决办法
7万
查看次数

标签 统计

javascript ×1

jquery ×1

twitter-bootstrap ×1