我有一个jquery对话框,我用这段代码打开它:
$(“#myDialog”)。dialog(“open”)。css(“maxHeight”,window.innerHeight - 150);
我在最后有css()以确保对话框不长于当前用户窗口,如果是,则将其剪切掉并创建一个垂直滚动条。
工作正常,但现在我想强制垂直滚动条到顶部,但我似乎无法让它工作。我试过把它放在上面一行之后:
$("#myDialog").scrollTop(0);
$("#myDialog").scrollTop();
我也试过这个:
$("#myDialog").dialog({
resizable: false,
height: 'auto',
open: function () {
$(this).scrollTop(0);
},
但是在对话框打开后似乎没有任何东西强迫垂直滚动条到顶部。
答案 0 :(得分:1)
将这两个选项添加到对话框中,如下所示,默认情况下,滚动位于顶部:
$("#myDialog").dialog({
maxHeight: window.innerHeight - 15,
overflow:'scroll'
});
使用类似的东西:
<div id="clickme">click me</div>
<div id="dialog" title="Dialog Title">
<p>ipt Library. Whether you're building highly interactive web applications or you just need to add a date picker to a form control, jQuery UI is the perfect choice.
jQuery UI is a curated set of user interface jQuery UI is a curated set.</p>
</div>
<script>
$( "#clickme" ).click(function( event ) {
$( "#dialog" ).dialog( "open" );
event.preventDefault();
});
$( "#dialog" ).dialog({
autoOpen: false,
width: 400,
maxHeight: window.innerHeight - 15,
overflow:'scroll',
buttons: [
{
text: "Ok",
click: function() {
$( this ).dialog( "close" );
}
},
{
text: "Cancel",
click: function() {
$( this ).dialog( "close" );
}
}
]
});
</script>
中查看我的代码