Jump to content
Search Community

Draggable top/left position is rounded down when using update method

xpo_greensock@knorex.com test
Moderator Tag

Warning: Please note

This thread was started before GSAP 3 was released. Some information, especially the syntax, may be out of date for GSAP 3. Please see the GSAP 3 migration guide and release notes for more information about how to update the code to GSAP 3's syntax. 

Recommended Posts

Hi everybody,

 

I met an issue that is when I set the Top/Left position manually in onPress function that position values are rounded down even I tried using autoRound: false.

 

I created an example via codepen. Is there any way to prevent that issue, please share me.

Thanks in advance!

 

See the Pen EmvOmw by duytan (@duytan) on CodePen

Link to comment
Share on other sites

Can you help us understand why you'd want to do that? Browsers always round the values anyway for display (unlike x/y transforms). I'm struggling to see any up-side to offering the ability to set top/left to sub-pixel values. And you're right, currently Draggable rounds those values. 

Link to comment
Share on other sites

Hi Jack, actually I am working on an app that allows user can design HTML5 element by dragging from A position to B position in percentage and pixel.

I met this issue when trying to convert percentage to pixel once user mouse down on the element. The element's position is lightly vibrated.

That is my previous topic: https://greensock.com/forums/topic/16365-draggable-topleft-in-pixel-and-percentage/

Link to comment
Share on other sites

Interesting. Hm, do you have a reduced test case that shows the "lightly vibrated" effect? My understanding was that browsers simply won't display top/left in anything bug whole pixel values anyway (regardless of if it's %-based or px-based), so I'm curious to see this in action. 

 

One other approach you could take is to use type:"x,y" instead of "left,top" and just change your conversion math that gets it to the %-based top/left values. Just an idea. The x/y can definitely do sub-pixel rendering, and it'd probably perform slightly faster too. 

  • Like 1
Link to comment
Share on other sites

Thanks for your feedback. That is clearer test case: 

See the Pen eWGRXE by duytan (@duytan) on CodePen

which using Draggable latest ver 1.19.1. The element is slightly vibrated when checking on Safari.

I can't use "x,y" type in my case because of the consistency.

 

By the way, I found the solution in my case by just using Draggable ver 1.18.0. 

In my opinion, I think you should keep previous behavior, should not round position values maybe it can cause some problems like my case.

Link to comment
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...