代码之家  ›  专栏  ›  技术社区  ›  Hermine D.

如何使用RJS滚动页面?

  •  0
  • Hermine D.  · 技术社区  · 15 年前

    如何将页面滚动到通过RJS插入的部分页面?

    page.insert_html :bottom, :comments, :partial => 'comment', :object => @comment
    
    1 回复  |  直到 14 年前
        1
  •  1
  •   Salil    15 年前

    您必须在页面中添加一个javascript方法,并从控件调用它。

    例如:-在example.html.erb中

    function scrollToDiv(id){
         // This method is used to scroll page 
    }
    

    在你的控制方法中

    page.insert_html :bottom, :comments, :partial => 'comment', :object => @comment
    page << "scrollToDiv('#{@comment.id}')"