Answer the question
In order to leave comments, you need to log in
Scroll, margin-top and Chrome?
Hello,
I need to make the side block sticky. position: fixed
you 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';
}
})
Answer the question
In order to leave comments, you need to log in
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question