【问题标题】:How to scroll the page with rjs?如何使用 rjs 滚动页面?
【发布时间】:2010-04-28 11:23:34
【问题描述】:

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

page.insert_html :bottom, :comments, :partial => 'comment', :object => @comment

【问题讨论】:

    标签: ruby-on-rails ajax rjs


    【解决方案1】:

    您必须在页面中添加一个 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}')"
    

    【讨论】:

      猜你喜欢
      • 2022-12-31
      • 1970-01-01
      • 2013-11-10
      • 2012-01-16
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多