Example of css3D+ animation (complete code attached)
This article brings you examples of css3D animation (complete code attached), which has certain reference value. Friends in need can refer to it. I hope it will be helpful to you.
Preface
I recently played around with using CSS to create 3D effects and wrote several demos, so I will summarize them in this blog. Before reading this blog, please first understand the properties of css 3D, such as: transform-style, transform-origin, transform, perspective.
Write a simple cube
1. We first use css to implement a cuboid. A cuboid has 6 sides. We write 6 li and wrap it with an ul. According to My experience in writing 3D animation is that it is best to have a parent element to wrap
<p> </p>
- 1
- 2
- 3
- 4
- 5
- 6
2. First set the width and height for .parent, and set the viewing distance and base point position for it.
.parent{ width: 800px; height: 400px; border: 1px solid #000; margin: 0 auto; perspective: 2000px; perspective-origin: -40% -80%; background: #000; }
3. Set the width, height and preserve-3d attributes of ul to retain the 3D transformation of the sub-element. All sub-elements li are absolutely positioned
ul{ width: 50px; position: relative; margin: 100px auto; transform-style : preserve-3d; } li{ width: 100px; height: 100px; background: rgba(255, 255, 0, 0.3); position: absolute; text-align: center; border: 3px solid greenyellow; }
The effect is as shown below As shown:
4. First write a face and set background for its background: rgba(255, 255, 0, 0.3 );
li:nth-child(1){ background: rgba(255, 255, 0, 0.3); transform: translateY(50px) rotateX(90deg); }
The effect is as shown below:
5. We have written the first face, and then we adjust the other 6 faces to become as shown in the picture below. The rotation direction of rotate will not be explained here. Friends who do not understand can check other documents by themselves.
/*上面*/ li:nth-child(1){ transform: translateY(-50px) rotateX(90deg); } /*下面*/ li:nth-child(2){ transform: translateY(50px) rotateX(90deg); } /*左面*/ li:nth-child(3){ transform: translateX(-50px) rotateY(90deg); } /*右面*/ li:nth-child(4){ transform: translateX(50px) rotateY(90deg); } /*前面*/ li:nth-child(5){ transform: translateZ(50px); } /*后面*/ li:nth-child(6){ transform: translateZ(-50px); }
The effect is as shown below:
1. The code is as follows:
nbsp;html> <meta> <meta> <meta> <title>书页2</title> <style> .container{ width: 1000px; height: 650px; background: #000; perspective: 2000px; border: 1px solid transparent; overflow: hidden; margin: 0 auto; perspective-origin: 10% 20%; } .cube{ width: 200px; height: 300px; transform-style: preserve-3d; margin:100px auto; position: relative; transform: rotateX(30deg); border-radius: 50%; padding: 60px; } .mian{ width: 200px; height: 300px; background-image: url(1.jpg); background-position:400px 0; position: absolute; border: 1px solid #ccc; transition: 2s; } /* .mian1:hover{ transform-origin: right; transform: rotateY(-60deg); } */ .mian1{ transform-origin: right; transform: translateX(-200px) rotateY(45deg); background-position: 0 0; } .mian3{ transform-origin: left; transform: translateX(200px) rotateY(45deg); background-position: 200px 0; } .mian3:hover{ transform: translateX(200px) rotateY(0deg); } .mian1:hover{ transform: translateX(-200px) rotateY(0deg); } </style> <p> </p><p> </p><p></p> <p></p> <p></p>
2. The code is as follows:
nbsp;html> <meta> <meta> <meta> <title>立方体</title> <style> *{ margin: 0; padding: 0; list-style: none; } .parent{ width: 1000px; margin: 0 auto; height: 600px; background: black; perspective: 5000px; perspective-origin: -40% -120%; border: 1px solid #000; } ul{ width: 100px; height: 300px; position: relative; margin:100px auto; transform-style: preserve-3d; animation: zuan 3s linear infinite; border: 1px solid greenyellow; } li{ width: 100px; height: 300px; background: rgba(0, 0, 0, 0.5); position: absolute; text-align: center; line-height: 100px; border: 3px solid greenyellow; } li:nth-child(1){ transform: rotateY(30deg) translateZ(-200px); } li:nth-child(2){ transform: rotateY(60deg) translateZ(-200px); background: rgba(255, 0, 0, 0.5); } li:nth-child(3){ transform: rotateY(90deg) translateZ(-200px); } li:nth-child(4){ transform: rotateY(120deg) translateZ(-200px); background: rgba(0, 0, 255, 0.5); } li:nth-child(5){ transform: rotateY(150deg) translateZ(-200px); } li:nth-child(6){ transform: rotateY(180deg) translateZ(-200px); background: rgba(255, 0, 255, 0.5); } li:nth-child(7){ transform: rotateY(210deg) translateZ(-200px); } li:nth-child(8){ transform: rotateY(240deg) translateZ(-200px); background: rgba(0, 255, 0, 0.5); } li:nth-child(9){ transform: rotateY(270deg) translateZ(-200px); } li:nth-child(10){ transform: rotateY(300deg) translateZ(-200px); background: rgba(0, 255, 255, 0.5); } li:nth-child(11){ transform: rotateY(330deg) translateZ(-200px); } li:nth-child(12){ transform: rotateY(360deg) translateZ(-200px); background: rgba(255, 255, 255, 0.5); } @keyframes zuan{ 0%{ transform: rotateY(0deg); } 100%{ transform: rotateY(360deg); } } </style> <p> </p>
How to achieve style effect css when the web page is loaded? (Multiple style examples)
How to use pure CSS to realize a smiling and meditating little monk
How to use css attributes to add font shadow effect ? (code demonstration)
The above is the detailed content of Example of css3D+ animation (complete code attached). For more information, please follow other related articles on the PHP Chinese website!

Hot AI Tools

Undresser.AI Undress
AI-powered app for creating realistic nude photos

AI Clothes Remover
Online AI tool for removing clothes from photos.

Undress AI Tool
Undress images for free

Clothoff.io
AI clothes remover

Video Face Swap
Swap faces in any video effortlessly with our completely free AI face swap tool!

Hot Article

Hot Tools

Notepad++7.3.1
Easy-to-use and free code editor

SublimeText3 Chinese version
Chinese version, very easy to use

Zend Studio 13.0.1
Powerful PHP integrated development environment

Dreamweaver CS6
Visual web development tools

SublimeText3 Mac version
God-level code editing software (SublimeText3)

Hot Topics

Using Bootstrap in Vue.js is divided into five steps: Install Bootstrap. Import Bootstrap in main.js. Use the Bootstrap component directly in the template. Optional: Custom style. Optional: Use plug-ins.

HTML defines the web structure, CSS is responsible for style and layout, and JavaScript gives dynamic interaction. The three perform their duties in web development and jointly build a colorful website.

React combines JSX and HTML to improve user experience. 1) JSX embeds HTML to make development more intuitive. 2) The virtual DOM mechanism optimizes performance and reduces DOM operations. 3) Component-based management UI to improve maintainability. 4) State management and event processing enhance interactivity.

WebdevelopmentreliesonHTML,CSS,andJavaScript:1)HTMLstructurescontent,2)CSSstylesit,and3)JavaScriptaddsinteractivity,formingthebasisofmodernwebexperiences.

To set up the Bootstrap framework, you need to follow these steps: 1. Reference the Bootstrap file via CDN; 2. Download and host the file on your own server; 3. Include the Bootstrap file in HTML; 4. Compile Sass/Less as needed; 5. Import a custom file (optional). Once setup is complete, you can use Bootstrap's grid systems, components, and styles to create responsive websites and applications.

There are two ways to create a Bootstrap split line: using the tag, which creates a horizontal split line. Use the CSS border property to create custom style split lines.

There are several ways to insert images in Bootstrap: insert images directly, using the HTML img tag. With the Bootstrap image component, you can provide responsive images and more styles. Set the image size, use the img-fluid class to make the image adaptable. Set the border, using the img-bordered class. Set the rounded corners and use the img-rounded class. Set the shadow, use the shadow class. Resize and position the image, using CSS style. Using the background image, use the background-image CSS property.

How to use the Bootstrap button? Introduce Bootstrap CSS to create button elements and add Bootstrap button class to add button text
