Through native JS, click events, mouse press, mouse lift and mouse move events, the drag and rotation of the 3D cube is realized, and the rotation angle is reflected on the interface in real time.
Implementation principle: By obtaining the coordinates when the mouse clicks on the screen and the coordinates when the mouse moves, the distance moved by the mouse on the X-axis and Y-axis is obtained, and the distance is assigned to the transform attribute in real time
Thus, the effect of 3d cube rotation can be achieved by changing the transform:rotate attribute value
HTML code block:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 |
|
CSS code block:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 |
|
JS code block:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 |
|
The above is the knowledge that the editor introduces to you based on the new css3 attribute transform and native js to realize mouse dragging 3d cube rotation. I hope it will be helpful to everyone. If If you have any questions, please leave me a message and I will reply to you in time. I would also like to thank you all for your support of the PHP Chinese website!
For more related articles based on the new css3 attribute transform and native js to realize mouse dragging 3d cube rotation, please pay attention to the PHP Chinese website!