[elixir! 52] 使用 PhoenixLiveView 调用 JS 代码

需求: 新内容出现时滚到到底端html

1 定义js钩子代码this

const Hooks = {}

Hooks.Scroll = {
  updated () {
    this.el.scrollTop = this.el.scrollHeight
  },
  mounted () {
    this.el.scrollTop = this.el.scrollHeight
  }
}

const liveSocket = new LiveSocket('/live', Socket, { hooks: Hooks })

2 在 html 元素上引用钩子code

<div phx-hook="Scroll">

很简单地实现了对js 代码的调用.htm

相关文章
相关标签/搜索