S
S
Seva2017-08-16 22:00:05
css
Seva, 2017-08-16 22:00:05

Scroll, margin-top and Chrome?

Hello,
I need to make the side block sticky. position: fixedyou can’t do it, flexbox is everywhere and everything will crumble. I do it like this:

var anchors = {
    textEndline: document.querySelector('.longRead__text').clientHeight + +document.querySelector('.longRead__text').offsetTop,
    el: document.querySelector('.anchors'),
    height: document.querySelector('.anchors').clientHeight + 50,
    offsetTop: document.querySelector('.anchors').offsetTop - 50  // 50 is a gutter
  }

  document.addEventListener('scroll', function(e) {
    if (window.scrollY > anchors.offsetTop && window.scrollY <  (anchors.textEndline - anchors.height)) {
      anchors.el.style.marginTop = window.scrollY - anchors.offsetTop + 'px';
    }
  })

In Firefox everything works fine, in chrome - the margin "catches up" with the scroll and the block twitches.
Has anyone come across? Is it being treated?
Thank you.

Answer the question

In order to leave comments, you need to log in

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question