Example introduction of css3 transform and native js to realize mouse dragging 3D cube rotation

高洛峰
Release: 2017-03-08 15:29:34
Original
2573 people have browsed it

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

Copy after login

CSS code block:

Copy after login

JS code block:

Copy after login

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!

Related labels:
source:php.cn
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template
About us Disclaimer Sitemap
php.cn:Public welfare online PHP training,Help PHP learners grow quickly!