Block change



  • I'd like a sydbar to get to the top as soon as the sydbar's top is hidden, and now it's working when we get to the sydbar's bottom.

    code:

    var change = document.getElementById('sidebar');
    

    var SourceBottom = change.getBoundingClientRect().bottom + window.pageYOffset;

    window.onscroll = function() {
    if (change.classList.contains('fixed') && window.pageYOffset < SourceBottom) {
    change.classList.remove('fixed');
    } else if (window.pageYOffset > SourceBottom) {
    change.classList.add('fixed');
    }
    };

    https://jsfiddle.net/dirkdirk/ugcpv9pg/27/



  • That's how you decided.

    var change = document.getElementById('sidebar');
    var top = document.getElementById('top');
    var SourceBottom = top.getBoundingClientRect().bottom + window.pageYOffset;
    window.onscroll = function() {
        if (change.classList.contains('fixed') && window.pageYOffset < SourceBottom) {
            change.classList.remove('fixed');
        } else if (window.pageYOffset > SourceBottom) {
            change.classList.add('fixed');
        }
    };
    

Log in to reply
 


Suggested Topics

  • 2
  • 2
  • 2
  • 2
  • 2
  • 2
  • 2
  • 2
  • 2
  • 2
  • 2
  • 2
  • 2
  • 2
  • 2