I am trying to save a table header corrected using the Javascript event scrollto control the table header property top.
This method seems to be very different depending on the browser and screen resolution (my main visitors to the site are Retina MBP). Currently, he stutters badly. It may seem like it works fine in this Fiddle, but it will actually be slow and noisy on your desktop.
https://jsfiddle.net/taylorpalmer/exp057a5/
I need to scroll the page and stick to the table title bar when you scroll it.
var allTh = document.querySelectorAll("th");
var leftCells = document.querySelectorAll(".fixed-col");
var latestKnownScrollX = 0;
var latestKnownScrollY = 0;
var ticking = false;
var onScroll = function() {
latestKnownScrollX = document.body.scrollLeft;
latestKnownScrollY = document.body.scrollTop;
requestTick();
}
function requestTick() {
if (!ticking) {
requestAnimationFrame(update);
}
ticking = true;
}
var immediate = true;
var update = function() {
console.log('scrolling');
ticking = false;
var currentScrollY = latestKnownScrollY;
var currentScrollX = latestKnownScrollX;
var translateHead = (currentScrollY) +"px";
for(var i=0; i < allTh.length; i++ ) {
allTh[i].style.top = translateHead;
}
var translateCell = currentScrollX + "px";
for(var i=0; i < leftCells.length; i++ ) {
leftCells[i].style.left = translateCell;
}
};
window.addEventListener("scroll", onScroll);
Things I've already tried:
- Usage
requestAnimationFrame()- Currently Implemented - - .
- - .
transform: translate() top -
, ,