To simulate a three-dimensional effect in a two-dimensional space, you need to convert the three-dimensional coordinates into two-dimensional coordinates. The most basic basis is: the farther the East and West are, the smaller the size is, and the closer the coordinates are to disappear points.
Pivoting formula:
Scale = fl/(fl + z );
Scale is the ratio of the size, between 0.0 and 1.0, fl is the distance from the observation point to the imaging surface, usually this value is fixed, z is the z axis of the three-dimensional space of the object.
Before writing these codes, I like to use object-oriented methods to describe these things I have written. For example, I need a scenario where a space can accommodate various objects, an object is an object, and an object is x, y, and z. In a scenario, you can insert any number of objects, and the object will take its coordinate value, it is displayed in a specific position of the scenario, and the scenario is responsible for the display position of the object.
For some demos, move the mouse and scroll wheel.
Effect 1
<! Doctype html> <pead> <meta http-equiv = "Content-Type" content = "text/html; charset = UTF-8 "/> <title> pseudo 3d pivoting effect </title> <style> html, body {padding: 0px; margin: 0px; height: 100%; width: 100%; overflow: hidden ;}# box {background: # ccc; height: 100%; border: 1px solid # ccc; position: relative; overflow: hidden;} # debug {width: 200px; background: # fff; border: 1px solid # ccc; position: absolute; left: 10px; top: 0px ;} </style> </pead> <body> </ptml>
[Ctrl + A select all Note: If you need to introduce external Js, You need to refresh it to execute]
Effect 2
<! Doctype html> <pead> <meta http-equiv = "Content-Type" content = "text/html; charset = UTF-8 "/> <title> pseudo 3d pivoting effect </title> <style> html, body {padding: 0px; margin: 0px; height: 100%; width: 100%; overflow: hidden ;}# box {background: # ccc; height: 100%; border: 1px solid # ccc; position: relative; overflow: hidden;} # debug {width: 200px; background: # fff; border: 1px solid # ccc; position: absolute; left: 10px; top: 0px ;} </style> </pead> <body> </ptml>
[Ctrl + A select all Note: If you need to introduce external Js, You need to refresh it to execute]
Effect 3
<! Doctype html> <pead> <meta http-equiv = "Content-Type" content = "text/html; charset = UTF-8 "/> <title> pseudo 3d pivoting effect </title> <style> html, body {padding: 0px; margin: 0px; height: 100%; width: 100%; overflow: hidden ;}# box {background: # fff; height: 100%; border: 1px solid # ccc; position: relative; overflow: hidden;} # debug {width: 200px; background: # fff; border: 1px solid # ccc; position: absolute; left: 10px; top: 0px ;} </style> </pead> <body> </ptml>
[Ctrl + A select all Note: If you need to introduce external Js, You need to refresh it to execute]
Effect 4
<! Doctype html> <pead> <meta http-equiv = "Content-Type" content = "text/html; charset = UTF-8 "/> <title> pseudo 3d pivoting effect </title> <style> html, body {padding: 0px; margin: 0px; height: 100%; width: 100%; overflow: hidden ;}# box {background: # ccc; height: 100%; border: 1px solid # ccc; position: relative; overflow: hidden;} # debug {width: 200px; background: # fff; border: 1px solid # ccc; position: absolute; left: 10px; top: 0px ;} </style> </pead> <body> </ptml>
[Ctrl + A select all Note: If you need to introduce external Js, You need to refresh it to execute]