gpt4 book ai didi

javascript - scrollIntoView() 没有将节点滚动到树的顶部

转载 作者:行者123 更新时间:2023-11-30 19:36:18 26 4
gpt4 key购买 nike

scrollIntoView() 函数有问题。我有一棵树和两个按钮:

  1. 首先将树滚动到底部节点
  2. 第二个将树滚动到顶部节点

我不知道我应该怎么做,这个滚动操作总是将节点滚动到树的顶部。我的意思是这个 fiddle 的情况:

http://jsfiddle.net/presto41/xzb62pw5/8/

如果您单击按钮 #button1(滚动到底部节点),那么树将滚动到底部节点 - 但底部节点不会位于树的顶部。它的工作方式为“仅显示节点。完成”。

在这种情况下,我希望滚动到底部节点将像滚动到顶部节点一样工作:

  1. 点击#button1(滚动到底部节点)
  2. 点击#button2(滚动到顶部节点)
  3. topNode在树的顶端

有什么想法吗?我试图通过 options 操纵这个 scrollIntoView() 函数但要么我做错了什么,要么它不能像我预期的那样工作。


Edit: I don't understand why anyone give me minus for that question. I made a research, I was trying to solve that problem by myself and I put clear description of my problem. It's irritating.


Edit 2: I haven't ids of these nodes. I've got just node as Fancytree.FancytreeNode object so I need a solution without operation on the node id.


Edit 3: this is my pseudocode witch is the most similar with original: http://jsfiddle.net/presto41/xzb62pw5/27/

最佳答案

我找到了解决方案。解决方案是函数:

function expandAndScrollTo(node) {
node.setExpanded(true).then(()=>{
node.span.scrollIntoView({behavior:'smooth', inline:'start'});
});}

关于javascript - scrollIntoView() 没有将节点滚动到树的顶部,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/55918696/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com