Javascript 如何滚动JQuery UI对话框中的流
我一直试图使用跟随滚动移动对话框与用户滚动,但没有成功Javascript 如何滚动JQuery UI对话框中的流,javascript,jquery,jquery-ui,jquery-dialog,Javascript,Jquery,Jquery Ui,Jquery Dialog,我一直试图使用跟随滚动移动对话框与用户滚动,但没有成功 <script> $(function() { $( "#dialog:ui-dialog" ).dialog( "destroy" ); $( "#dialog-report-problem-form" ).dialog({ autoOpen: true, height: 550, width: 700, modal: true,
<script>
$(function() {
$( "#dialog:ui-dialog" ).dialog( "destroy" );
$( "#dialog-report-problem-form" ).dialog({
autoOpen: true,
height: 550,
width: 700,
modal: true,
buttons: {
"<?= $this->translate('REPORT_PROBLEM'); ?>": function() {
reportProblem();
},
"<?= $this->translate('CANCEL'); ?>": function() {
$( this ).dialog( "close" );
}
},
close: function() {
}
});
$.scrollFollow("#dialog-report-problem-form",{speed: 10});
});
</script>
有人知道如何修复或其他基于jquery的解决方案来跟踪用户scroll吗?scrollFollow插件似乎有很大的缺陷,开发中断(上次更新于2008年)
- 当您将它与
一起使用时,默认选项值未设置,因此会出现许多与您所遇到的错误类似的错误$.scrollFollow()
- 将其与
一起使用时,无法正确获取主选项容器,因此它实际上无法工作$(…).scrollFollow
(function(wnd, $) {
// query for elements once
var $dlg = $("#dialog-report-problem-form").parent(),
$wnd = $(wnd),
// get the initial position of dialog
initialTop = $dlg.offset().top - $wnd.scrollTop();
$wnd.scroll(function() {
// when qscrolling, animate the 'top' property
$dlg.stop()
.animate({
"top": ($wnd.scrollTop() + initialTop) + "px"
}, "slow");
})
.resize(function() {
// in case of resize, re-set the initial top position of the dialog
initialTop = $dlg.offset().top - $wnd.scrollTop();
});
// if you close/open the dialog, it will mess up the 'initialTop'
// this will re-set the correct 'initialTop' when the dialog opens again
$dlg.bind('dialogcreate dialogopen', function(e) {
initialTop = $dlg.offset().top - $wnd.scrollTop();
});
})(window, jQuery);
工作示例。您好,我看到了您的工作示例,但当我插入模板时,它总是不断下降。查看页脚并单击“报告问题”查看对话框大小和windows高度影响我看到您将脚本与对话框内容一起加载,因此无法调试脚本并检查可能出现的问题。你能把它放在
script.js
后面的$(“#报告问题”).html(html)代码>?更改行initialTop=$dlg.offset().top
toinitialTop=$dlg.offset().top-$wnd.scrollTop()代码>
box.cont.offset() is null
(function(wnd, $) {
// query for elements once
var $dlg = $("#dialog-report-problem-form").parent(),
$wnd = $(wnd),
// get the initial position of dialog
initialTop = $dlg.offset().top - $wnd.scrollTop();
$wnd.scroll(function() {
// when qscrolling, animate the 'top' property
$dlg.stop()
.animate({
"top": ($wnd.scrollTop() + initialTop) + "px"
}, "slow");
})
.resize(function() {
// in case of resize, re-set the initial top position of the dialog
initialTop = $dlg.offset().top - $wnd.scrollTop();
});
// if you close/open the dialog, it will mess up the 'initialTop'
// this will re-set the correct 'initialTop' when the dialog opens again
$dlg.bind('dialogcreate dialogopen', function(e) {
initialTop = $dlg.offset().top - $wnd.scrollTop();
});
})(window, jQuery);