Small mathematics is not good.
Now, every time I see the method in the Math object, a white light will flash in my mind: What is this method?
It seems that ceil, floor, random, and round have been used in the past.
Floor (), minimum value
Ceil (), maximum value
Round (), returns the nearest value. When the value is exactly half (0.5), the maximum value is obtained.
Random (), needless to say, the range is 0 to 1 decimal places
Today, Math. abs () is used to obtain the absolute value.
Never used
Max (,) and min (,) are two big and small values after comparison.
All types in js are weak data types. That is to say, no matter what type is declared with var, the specific type depends on the value you pay for it.
Sometimes, for the sake of logical judgment, numbers and Boolean operations are used directly.
For example:
Specified usel. prototype = {glue: false, var totalMoved = this. vertical? (This. dy % this. myDivHeight)/this. myDivHeight * 100) *-1: (this. dx % this. myDivWidth)/this. myDivWidth * 100) *-1; // get a percentage of movement. touchMove: function (e) {if (! This. okToMove) {oldStateOkToMove = this. okToMove; this. okToMove = this. glue? Math. abs (totalMoved)> this. glue & Math. abs (totalMoved) <(100-this. glue): true; if (this. okToMove &&! OldStateOkToMove) {$. trigger (this, "movestart", [this. el]) ;}}
Tested:
It can be seen that when -- is executed, glue is still 0. After execution, glue is changed to-1.
If JavaScript does not understand anything, you can test it on the console! This is one of the secrets of learning.
In the previous example, there is a very long sentence:
Var totalMoved = this. vertical? (This. dy % this. myDivHeight)/this. myDivHeight * 100) *-1: (this. dx % this. myDivWidth)/this. myDivWidth * 100) *-1;
Note that the motion distance is taken as a percentage and the operator % is used.
| % |
Returns the remainder (reserved integer) |
* = 5% 2 |
X = 1 |
This is the only arithmetic operator except addition, subtraction, multiplication, division, and so on.
In addition, the three-object operator is long and must be clear? The first is the condition, and the question mark is followed by the true and false values respectively.
Mathematics