Skip to content

Commit

Permalink
fix: always round scrollLeft
Browse files Browse the repository at this point in the history
Hopefully that will fix all the subpixel-related issues.

Closes: #124, #81
  • Loading branch information
alistair3149 committed Apr 24, 2024
1 parent 391002a commit 99413c7
Showing 1 changed file with 8 additions and 3 deletions.
11 changes: 8 additions & 3 deletions modules/ext.tabberNeue.legacy/ext.tabberNeue.legacy.js
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,11 @@ function initTabber( tabber, count ) {
nextButton = document.createElement( 'div' ),
indicator = document.createElement( 'div' );

// scrollLeft can return decimals while offset are always integer
const roundScrollLeft = function ( val ) {
return Math.ceil( val );
};

const buildTabs = function () {
const
tabPanels = tabber.querySelectorAll( ':scope > .tabber__section > .tabber__panel' ),
Expand Down Expand Up @@ -135,7 +140,7 @@ function initTabber( tabber, count ) {
const width = getActualSize( activeTab, 'width' );

indicator.style.width = width + 'px';
indicator.style.transform = 'translateX(' + ( activeTab.offsetLeft - tabList.scrollLeft ) + 'px)';
indicator.style.transform = 'translateX(' + ( activeTab.offsetLeft - roundScrollLeft( tabList.scrollLeft ) ) + 'px)';
indicator.style.transition = '';

// Do not animate when user prefers reduced motion
Expand Down Expand Up @@ -172,7 +177,7 @@ function initTabber( tabber, count ) {
return;
}

const scrollLeft = tabList.scrollLeft;
const scrollLeft = roundScrollLeft( tabList.scrollLeft );

// Scroll to the start
if ( scrollLeft <= 0 ) {
Expand Down Expand Up @@ -208,7 +213,7 @@ function initTabber( tabber, count ) {
} else if ( matchMedia( '(hover: hover)' ).matches ) {
const scrollOffset = header.offsetWidth / 2;
const scrollTabs = function ( offset ) {
const scrollLeft = tabList.scrollLeft + offset;
const scrollLeft = roundScrollLeft( tabList.scrollLeft ) + offset;
// Scroll to the start
if ( scrollLeft <= 0 ) {
tabList.scrollLeft = 0;
Expand Down

0 comments on commit 99413c7

Please sign in to comment.