Giter Club home page Giter Club logo

Comments (8)

kapooramit avatar kapooramit commented on June 23, 2024 1

@tscanlin: Thanks for asking. I fixed it. What I meant was that if I manually scroll only the tocbot container, the page (js-toc-content) should not scroll with it. I managed to do it by checking when mouse enters the tocbot div area and at that time, stop content from scrolling. And when it comes out, I enabled content scrolling.

Thanks again!!

from tocbot.

kapooramit avatar kapooramit commented on June 23, 2024

Ok. I found this: #114

So I tried and here is the code that is not working for me:

           function UpdateVisibleToc() {
                var tocs = document.getElementsByClassName("js-toc");
                if (tocs.length > 0) {
                    var activeItem = tocs[0].getElementsByClassName("is-active-link");
                    if (activeItem.length > 0) {
                        tocs[0].scrollTop = activeItem[0].offsetTop;
                    }
                }
                
            }
            window.onscroll = () => UpdateVisibleToc();

            //Initialize tocbot
            tocbot.init({
                tocSelector: ".js-toc",
                contentSelector: ".js-toc-content",
                headingSelector: "h2,h3,h4",
                hasInnerContainers: false,
                collapseDepth: 4, 
                scrollSmooth: true,
                scrollSmoothDuration: 420,
                headingsOffset: 100,
                scrollSmoothOffset: -100,
                scrollEndCallback:  e => UpdateVisibleToc(),
            });

But if I change UpdateVisibleToc() to the following, it works but not smoothly as it should:


function UpdateVisibleToc() {
       $('#stickytoc').scrollTop($('.is-active-link').offset().top);
}

I am not sure what I am doing wrong so here is the gif showing what's happening...

Here is the html code

     <div id="onthispage_wrapper">
         <div id="onthispageheader">
              On this page
         </div>
         <div class="ks-onthispage" id="stickytoc">
              <nav class="ks-stickytoc js-toc" id="onthispage"></nav>
         </div>
      </div> 

#onthispageheader and #stickytoc are fixed. To ensure that #stickytoc doesn't bump into the footer when footer is coming up, I calculate its height using footer.top as soon as footer becomes visible and apply it using JavaScript shown below;

function setOnThisPageBottom (){

    var footer = document.getElementById("copyright").getBoundingClientRect();
    var footerTop = footer.top;
    var tocbotBottom = document.getElementById("stickytoc").getBoundingClientRect().bottom;

    if (footerTop < window.innerHeight)
    {
        var onThisPageHeight = (footerTop - 200);
        $("#stickytoc").css({ height: onThisPageHeight });
    }
    else
    {
        document.getElementById("stickytoc").style.height = "";    
    }
}

The above function is set to be called after DOM is ready (page loaded) as well as on scrolling.
So now the question is what will work in my case?

tocbot_scrollingdivsync

from tocbot.

kapooramit avatar kapooramit commented on June 23, 2024

@tscanlin , @xoofx : Would you please suggest?

from tocbot.

tscanlin avatar tscanlin commented on June 23, 2024

hmm, this functionality should be built into tocbot itself since the above PR you mentioned merged. If you make the height of the window small and test here it should work and scroll the toc:
http://tscanlin.github.io/tocbot/
PR: https://github.com/tscanlin/tocbot/pull/197/files

Can you share a link / example that reproduces this so we can try to help? Maybe try using behavior: scroll-smooth css would help on that container?

from tocbot.

kapooramit avatar kapooramit commented on June 23, 2024

Hi @tscanlin - thank you. I tried with scroll-behavior: smooth but no go. As always, because the code is IP protected, I have sent you email with link to live site. I have disabled my custom code to handle the syncing, that is, the following one is now disabled assuming tocbot should have handled this natively:

function UpdateVisibleToc() {
       $('#stickytoc').scrollTop($('.is-active-link').offset().top);
}

I also tried reducing the height of the window and scrolling but still the same.

Eagerly waiting for your response! Thank you. :-)

from tocbot.

tscanlin avatar tscanlin commented on June 23, 2024

Hey, thanks for sharing the example!

Can you try adding the following properties to .js-toc:

overflow-y: auto; /* could also be 'scroll' */
height: 200px;

If you want the toc to be a different height you could do something like calc(100vh - 300px) instead. Choosing a smaller height is just easier for testing.

Hope that helps! Let me know if you are still running into issues.

from tocbot.

kapooramit avatar kapooramit commented on June 23, 2024

from tocbot.

tscanlin avatar tscanlin commented on June 23, 2024

Glad I've bee helpful! :)

Though I'm not sure what you mean by "scrolling the tocbot output manually should not scroll the content"

Could you share a video perhaps to help explain?

from tocbot.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.