To implement the center of the element:
A is the width or height of the element, and L is the width or height of the page
e.style.left=l/2-a/2+ ' px ';
Implementing the movement of elements
The left margin of the mouse distance element on the element is derived from the MouseDown event.
C=f-h
The left margin of the element distance to the page is drawn, in the MouseMove event
e.style.left=f-c+ ' px '
Implement collision detection of elements
L1 and R1 are the same element, L2 and R2 are the same element, L1,r1 imagined as the left end of the page, L2,r2 imagined as the right end of the page
L1,R1 is the left side of the element page distance, L2,R2 is the right side of the element page distance
As long as the satisfaction of L1<L2<-->R2<R1 is satisfied, L2 and R2 any point in the range of L1 and R1, then the x-axis collision is established
Loop I=L2<-->R2
In the loop body if (L1<I<R1)
Boolean values X_flag and Y_flag record X-and y-axis collision detection data, with (and) (&&) operations
Knowledge Point Supplement:
1<x && x<6//The value of x is true between 1~6 and true.
1<x | | X<6//The value of x is X>1 infinity, x<6 is true when infinite number, one of which is true
JS exercise function Code and image