Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/javascript/418.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/jquery/81.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/3/heroku/2.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Javascript 如何滚动JQuery UI对话框中的流_Javascript_Jquery_Jquery Ui_Jquery Dialog - Fatal编程技术网

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
to
initialTop=$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);