This article uses native JS, click events, mouse press, mouse lift and mouse move events to realize the drag and rotation of the 3D cube, and reflect the rotation angle to 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. 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:
//X轴旋转角度 //Y轴旋转角度
1 2 3 4 5 6
CSS code block:
JS code block:
The above is the entire content of this article. I hope it will be helpful to everyone’s learning and I hope you will support me a lot. PHP Chinese website.
The above is the detailed content of Example introduction of css3 transform and native js to realize mouse dragging 3D cube rotation. For more information, please follow other related articles on the PHP Chinese website!