2012-01-16 53 views
3

我一直在尝试使用遵循滚动到与移动用户滚动一起对话框,但没有成功如何滚动流JQuery用户界面对话框

<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> 

<div id="dialog-report-problem-form" title="<?= $this->translate('REPORT_PROBLEM'); ?>"> 
    <?= $this->form ?> 
</div> 

我已经收到了错误

box.cont.offset() is null 

有谁知道怎么能解决或其他基于jQuery的解决方案来跟踪用户滚动?

回答

3

插件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); 

工作示例jsfiddle

+0

嗨,我看到你的工作示例,但是当我插入到我的模板中时,它总是停下来。看http://yourlnk.com/67转到页脚并单击报告问题 – dextervip 2012-01-16 17:37:59

+0

看起来像对话框的大小和窗口高度影响 – dextervip 2012-01-17 05:52:07

+0

我看到您加载脚本以及对话框内容,因此无法调试它并且检查可能是什么问题。你可以把它放在'$(“#report-problem”)。html(html);''后面的'script.js'中吗? – 2012-01-17 06:37:30

相关问题