javascript - Scroll Event - Seamless Translation Displacement -
adding event listener element scroll event (and wheel too?) i'm trying use displacement (n.scrollleft , n.scrolltop) position element in such way appears not scroll. example, freezing table headers in table when scrolling down stay on top.
i think there fundamental difference between browsers on how scroll event used because in chrome looks good, safari , firefox event seems fire bit late (page scrolls, headers snap shortly after).
seamless on chrome, jittery on safari & firefox:
var container = document.queryselector('#container'); var table = document.queryselector('table'); var topheaders = [].concat.apply([], document.queryselectorall('tbody th')); container.addeventlistener('scroll', updatetabletranslations, false); container.addeventlistener('wheel', updatetabletranslations, false); function updatetabletranslations(e){ var x = container.scrollleft; var y = container.scrolltop; topheaders.foreach(function (topheader, i) { topheader.style.transform = translate(0, y); }); } function translate(x, y) { return 'translate(' + x + 'px, ' + y + 'px)'; }
https://jsfiddle.net/17lqy0m4/1/
is using scroll displacement right way go this? if so, how can working way like.
Comments
Post a Comment