Javascript Simulated 3D scenario effect code Packaging

Source: Internet
Author: User

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]

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.