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

Slide postions of by one pixel #1780

Open
hannesdorn opened this issue Apr 22, 2020 · 6 comments
Open

Slide postions of by one pixel #1780

hannesdorn opened this issue Apr 22, 2020 · 6 comments

Comments

@hannesdorn
Copy link

If the width of the slides is not an integer, it happes, that the position of the slides are not correctly calculated.
if (slider.isFirefox) { target = (vertical) ? "translate3d(0," + target + ",0)" : "translate3d(" + (parseInt(target)+'px') + ",0,0)"; } else { target = (vertical) ? "translate3d(0," + target + ",0)" : "translate3d(" + ((slider.vars.rtl?-1:1)*parseInt(target)+'px') + ",0,0)"; }
The problem is, that if width is a float, the offset for translate3d is calculated wrong.
Fix: change parseInt to parseFloat and everything is good.

@BenUniqcode
Copy link

Thank you @hannesdorn !

This issue still exists in the version of Flexslider that is bundled with WooCommerce (at least as of 4.9.1 - I haven't tried 5.x yet). At some browser sizes, I was getting a tiny sliver of the previous image on the left of the current one. It's only noticeable if the two images have different backgrounds of course, so most people will probably never notice it. Sometimes it's 1px wide, sometimes 2px, sometimes nothing. It was driving me mad. And I see on StackOverflow and elsewhere, various people have noticed this for years, and suggested various fixes. But your fix is the one that works.

The code in WooCommerce is different to the version on here, despite having the same version number. All I had to do is change the parseInt in this line:
target = (vertical) ? "translate3d(0," + target + ",0)" : "translate3d(" + (parseInt(target)+'px') + ",0,0)";
to parseFloat and the problem is fixed.

@petertwise
Copy link

+1 - also running into this issue in the WooCommerce bundled version.

Any way to fix without manually patching WooCommerce plugin files?

@petertwise
Copy link

Screen Shot 2021-03-10 at 4 36 04 PM

@freezvd
Copy link

freezvd commented May 27, 2021

My way...

woocommerce div.product div.images .woocommerce-product-gallery__image img {
width: 99%;
margin: auto;
}

@lucasbasquerotto
Copy link

lucasbasquerotto commented Jul 15, 2021

Changing parseInt() to parseFloat() didn't work in my case. I was able to fix this issue changing:

slider.computedW = slider.itemW - slider.boxPadding

to:

to slider.computedW = slider.itemW - slider.boxPadding + 1

at:

slider.computedW = slider.itemW - slider.boxPadding;

The cases in which the image would be shown correctly (without being off by 1 pixel), with the change above, lose the rightmost pixels, which is acceptable in my case, and most probably won't be noticed by the users (it's much better than having 1 less pixel at the right, that can be clearly seen by users).

@Andreslav
Copy link

Faced with this problem. Replacing parseInt with parseFloat helped.

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

6 participants