1

I've got the problem with scrollIntoView() function. I've got a tree and two buttons:

  1. first of them will scroll tree to bottom node
  2. second will scroll tree to top node

I don't know what I should to do that this scroll operation will always scroll node to top of tree. I mean about situation from this fiddle:

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

If you will click on button #button1 (Scroll to bottom node) then tree will be scroll to the bottom node - but bottom node will not be on the top of tree. It's working as "just show node. Done".

I want that scroll to bottom node will be work as scroll to top node in this scenario:

  1. click on #button1 (Scroll to bottom node)
  2. click on #button2 (Scroll to top node)
  3. topNode is on the top of tree

Any ideas? I was trying to manipulate this scrollIntoView() function by options but either I was doing something wrong or it can't works as I expect.


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/

Presto
  • 888
  • 12
  • 30

2 Answers2

2

I found the solution. The solution is function:

function expandAndScrollTo(node) {
       node.setExpanded(true).then(()=>{
       node.span.scrollIntoView({behavior:'smooth', inline:'start'});
  });}
Presto
  • 888
  • 12
  • 30
  • 1
    Thanks, `node.scrollIntoView()` did nothing but `node.span.scrollIntoView()` did the trick – Sean T Jan 30 '20 at 15:43
1

Use of scrollIntoView() is for to scroll the element with id="content" into the visible area of the browser window:

    var el = document.getElementById("content");
    el.scrollIntoView();

however you can use

    function scrollToBottom(){
       var eldiv = document.getElementById("content");
       eldiv.scrollTop = div.scrollHeight - div.clientHeight;
    }
    function scrollToTop(){
       var eldiv = document.getElementById("content");
       eldiv.scrollTop = 0;
    }
Mayur Baldha
  • 126
  • 1
  • 15