Jump to content
GreenSock

Search In
  • More options...
Find results that contain...
Find results in...
hayesmaker

Typo in ThrowProps Plugin docs?

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

Hiya, I just wondered if this line in the ThrowProps plugin docs was correct or a typo:

 

top = ((i / gridColumns) | 0) * gridHeight;

 

should it be this?

 

top = ((i / gridColumns) || 0) * gridHeight;

 

or am I missing some fundamental law of javascript? :)

Link to comment
Share on other sites

Without going to the docs and trying to figure out the sample, a single pipe is valid javascript: Bitwise OR.  It can sometimes be used as a fast way to truncate a float to an integer.

 

If the sample is working, it's safe to say it's probably intentional.

  • Like 3
Link to comment
Share on other sites

Yep, jamie is exactly right (as usual). It's not a typo. It's a faster way to do Math.floor(). 

//slower:
top = Math.floor(i / gridColumns) * gridHeight;

//about 4x faster
top = ((i / gridColumns) | 0) * gridHeight;

Think of it as a way to just drop off the decimal from a number.

  • Like 3
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.
×