Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

One per frame last item breaks depending on OS #287

Open
drdreo opened this issue Sep 18, 2017 · 1 comment
Open

One per frame last item breaks depending on OS #287

drdreo opened this issue Sep 18, 2017 · 1 comment

Comments

@drdreo
Copy link

drdreo commented Sep 18, 2017

I implented the one per frame sly scroll and it worked perfectly fine on macOS in the newest Chrome.
But then i switched to a windows pc which uses the same chrome and the last item always breaks into new line. Appearing here in the references tab: Portfolio

I tested the mac version of the website on the same monitor, therefore, screen size ain't the problem.
I did not distinguish or coded anything different for browsers or os.
Here the reproduced JSFiddle. Tested it on macOS and it shows all 3 items in perfect alignment. On Windows, same screen, same browser, last item breaks.

Is there a fix to that problem?

@botondcs
Copy link

botondcs commented Oct 29, 2019

I implemented item based horizontal basic and have the same issue. It does appear on some screen sizes but not on others, I can't find any pattern in that behaviour.

I think it is a rounding problem. When I wait for all elements to render and then reduce say the margin of the last element by 1px it fits into the first line again.

This fixed it for now (the margin here is 0.25rem smaller than normal):
$( '.class' ).last().css( 'margin', '0 1rem 0 0' );

This goes right after inits and reloads:
sly.init();
sly.reload();

EDIT:

The solution above did not work all the time because the rounding seems to happen on each element not on their sum, so the more elements there are, the more rounding happens. Instead I now calculate the width of each element including comma values and round it up, and then resize the parent (aka slidee).

var totalWidth = 0;
var elementWidth = 0
var elementMargin = 0;
slyElement.each( function() {
  elementWidth = Math.ceil( $( this )[0].getBoundingClientRect().width );
  elementMargin = parseInt( $( this ).css( 'margin-right' ) );
  totalWidth = totalWidth + elementWidth + elementMargin;
} );
slySlidee.width( totalWidth );

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants