Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[UX] Approximate scroll when we click on sidebar menu title #6

Closed
nodablock opened this issue May 8, 2020 · 2 comments
Closed

[UX] Approximate scroll when we click on sidebar menu title #6

nodablock opened this issue May 8, 2020 · 2 comments

Comments

@nodablock
Copy link

nodablock commented May 8, 2020

When we click on an element of the left side menu , the scroll brings it (approximately) to the content, sometimes at the wrong section.

For example, that link should bring to the video section, but it bring it to the middle of the content:

Screen Recording 2020-05-08 at 05 31 PM

I think the correct behaviour would be to bring it exactly to the heading title?

@onweru
Copy link
Owner

onweru commented May 12, 2020

I think the correct behaviour would be to bring it exactly to the heading title?

👍

@nodablock
Copy link
Author

nodablock commented May 28, 2020

Figured out that temp solution with jquery (we can do without) by hiding the top menu bar.
That code also solves #7

_nav.sass:

.nav-up 
  top: -100px;

head.html

<script src="https://code.jquery.com/jquery-3.5.1.slim.min.js" integrity="sha256-4+XzXVhsDmqanXGHaHvgh1gMQKX40OUvDEBTu8JcmNs=" crossorigin="anonymous"></script>

index.js:

$(function() {

    var hasClicked = false;

    // hide bar when clicking on a menu item
    $(".toc_item a").on('click', function(event) {
      hasClicked = true;
      $('.nav_header').removeClass('nav-down').addClass('nav-up');
    });

      // Hide Header on on scroll down
      var didScroll;
      var lastScrollTop = 0;
      var delta = 50;
      var navbarHeight = $('.nav_header').outerHeight();
      $(window).scroll(function(event){
          didScroll = true;
      });

      setInterval(function() {
          if (didScroll) {
              hasScrolled();
              didScroll = false;
              hasClicked = false;
          }
      }, 500);

      function hasScrolled() {
          var st = $(this).scrollTop();

          // Make sure they scroll more than delta
          if(Math.abs(lastScrollTop - st) <= delta)
              return;

          // If they scrolled down and are past the navbar, add class .nav-up.
          // This is necessary so you never see what is "behind" the navbar.
          if (st > lastScrollTop && st > navbarHeight){
              // Scroll Down
              $('.nav_header').removeClass('nav-down').addClass('nav-up');
          } else {
              // Scroll Up
              if(st + $(window).height() < $(document).height()) {
                if (hasClicked != true) {
                  $('.nav_header').removeClass('nav-up').addClass('nav-down');
                }
              }
          }
          lastScrollTop = st;
      }

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants