先来看一下效果:http://1.huizit1.applinzi.com/CSS/transform_3D/img_3D.html
布局结构:
<div class="container"> <img src="/static/imghwm/default1.png" data-src="../Img/1.jpg" class="lazy" alt="CSS3实现3D效果的图片墙_html/css_WEB-ITnose" > <img src="/static/imghwm/default1.png" data-src="../Img/2.jpg" class="lazy" alt="CSS3实现3D效果的图片墙_html/css_WEB-ITnose" > <img src="/static/imghwm/default1.png" data-src="../Img/3.jpg" class="lazy" alt="CSS3实现3D效果的图片墙_html/css_WEB-ITnose" > <img src="/static/imghwm/default1.png" data-src="../Img/4.jpg" class="lazy" alt="CSS3实现3D效果的图片墙_html/css_WEB-ITnose" > <img src="/static/imghwm/default1.png" data-src="../Img/5.jpg" class="lazy" alt="CSS3实现3D效果的图片墙_html/css_WEB-ITnose" > <img src="/static/imghwm/default1.png" data-src="../Img/6.jpg" class="lazy" alt="CSS3实现3D效果的图片墙_html/css_WEB-ITnose" > <img src="/static/imghwm/default1.png" data-src="../Img/7.jpg" class="lazy" alt="CSS3实现3D效果的图片墙_html/css_WEB-ITnose" > <img src="/static/imghwm/default1.png" data-src="../Img/8.jpg" class="lazy" alt="CSS3实现3D效果的图片墙_html/css_WEB-ITnose" > <img src="/static/imghwm/default1.png" data-src="../Img/9.jpg" class="lazy" alt="CSS3实现3D效果的图片墙_html/css_WEB-ITnose" > <img src="/static/imghwm/default1.png" data-src="../Img/10.jpg" class="lazy" alt="CSS3实现3D效果的图片墙_html/css_WEB-ITnose" > </div>
CSS3中新增了translate-style和perspective属性,要让图片有3D的效果就要添加这两个属性,具体的解释这里不再赘述,可以看这篇文章来理解:http://www.zhangxinxu.com/wordpress/2012/09/css3-3d-transform-perspective-animate-transition/
给container添加translate-style为preserve-3d,添加perspective: 2000px;
这里一共10张图片,为了让10张图片围成一个圆,需要添加position属性为absolute,设置宽度相同,居中,这时所有图片都重合在了一起。每张图片绕Y轴旋转36*i(i:0->9)度(rotateY),然后每张图片在Z轴方向移动相同的距离(translateZ),这个距离能保证图片不重合在一起就行。这时图片就围成了一个环状,并且是有3D效果的。然后给container添加动画属性让其绕Y轴不停旋转(rotateY),这时动画就出现了。
注意:给图片添加的属性transform: rotateY(0deg) translateZ(350px);rotateY和translateZ的位置不能交换,因为先旋转后移动和先移动后旋转的效果是不一样的。
这里我给container添加了背景颜色来参考图片的相对位置和旋转轴。
如果要用鼠标点击来切换图片的话,只需要每次点击之后container的旋转角度加36度就可以。
贴上代码:
1 <!DOCTYPE html> 2 <html lang="en"> 3 <head> 4 <meta charset="UTF-8"> 5 <title>img_3D</title> 6 </head> 7 <style type="text/css"> 8 @keyframes an1{ 9 0%{10 transform: rotateY(0deg) ;11 }12 50%{13 transform: rotateY(180deg) ;14 }15 100%{16 transform: rotateY(360deg) ;17 }18 }19 .container{20 width: 900px;21 height: 400px;22 background: rgba(255,0,0,0.5);23 /*opacity: 0.3;*/24 25 margin: 200px auto;26 perspective: 2000px;27 transform-style: preserve-3d;28 animation: an1 10s linear 0s infinite;29 }30 .container img{31 width: 200px;32 height: auto;33 margin: auto;34 top: 0;35 bottom: 0;36 left: 0;37 right: 0;38 position: absolute;39 }40 .container img:nth-child(1){41 transform: rotateY(0deg) translateZ(350px);42 }43 .container img:nth-child(2){44 transform: rotateY(36deg) translateZ(350px);45 }46 .container img:nth-child(3){47 transform: rotateY(72deg) translateZ(350px);48 }49 .container img:nth-child(4){50 transform: rotateY(108deg) translateZ(350px);51 }52 .container img:nth-child(5){53 transform: rotateY(144deg) translateZ(350px);54 }55 .container img:nth-child(6){56 transform: rotateY(180deg) translateZ(350px);57 }58 .container img:nth-child(7){59 transform: rotateY(216deg) translateZ(350px);60 }61 .container img:nth-child(8){62 transform: rotateY(252deg) translateZ(350px);63 }64 .container img:nth-child(9){65 transform: rotateY(288deg) translateZ(350px);66 }67 .container img:nth-child(10){68 transform: rotateY(324deg) translateZ(350px);69 }70 </style>71 <body>72 <div class="container">73 <img src="/static/imghwm/default1.png" data-src="../Img/1.jpg" class="lazy" alt="CSS3实现3D效果的图片墙_html/css_WEB-ITnose" >74 <img src="/static/imghwm/default1.png" data-src="../Img/2.jpg" class="lazy" alt="CSS3实现3D效果的图片墙_html/css_WEB-ITnose" >75 <img src="/static/imghwm/default1.png" data-src="../Img/3.jpg" class="lazy" alt="CSS3实现3D效果的图片墙_html/css_WEB-ITnose" >76 <img src="/static/imghwm/default1.png" data-src="../Img/4.jpg" class="lazy" alt="CSS3实现3D效果的图片墙_html/css_WEB-ITnose" >77 <img src="/static/imghwm/default1.png" data-src="../Img/5.jpg" class="lazy" alt="CSS3实现3D效果的图片墙_html/css_WEB-ITnose" >78 <img src="/static/imghwm/default1.png" data-src="../Img/6.jpg" class="lazy" alt="CSS3实现3D效果的图片墙_html/css_WEB-ITnose" >79 <img src="/static/imghwm/default1.png" data-src="../Img/7.jpg" class="lazy" alt="CSS3实现3D效果的图片墙_html/css_WEB-ITnose" >80 <img src="/static/imghwm/default1.png" data-src="../Img/8.jpg" class="lazy" alt="CSS3实现3D效果的图片墙_html/css_WEB-ITnose" >81 <img src="/static/imghwm/default1.png" data-src="../Img/9.jpg" class="lazy" alt="CSS3实现3D效果的图片墙_html/css_WEB-ITnose" >82 <img src="/static/imghwm/default1.png" data-src="../Img/10.jpg" class="lazy" alt="CSS3实现3D效果的图片墙_html/css_WEB-ITnose" >83 </div>84 </body>85 </html>

The function of HTML is to define the structure and content of a web page, and its purpose is to provide a standardized way to display information. 1) HTML organizes various parts of the web page through tags and attributes, such as titles and paragraphs. 2) It supports the separation of content and performance and improves maintenance efficiency. 3) HTML is extensible, allowing custom tags to enhance SEO.

The future trends of HTML are semantics and web components, the future trends of CSS are CSS-in-JS and CSSHoudini, and the future trends of JavaScript are WebAssembly and Serverless. 1. HTML semantics improve accessibility and SEO effects, and Web components improve development efficiency, but attention should be paid to browser compatibility. 2. CSS-in-JS enhances style management flexibility but may increase file size. CSSHoudini allows direct operation of CSS rendering. 3.WebAssembly optimizes browser application performance but has a steep learning curve, and Serverless simplifies development but requires optimization of cold start problems.

The roles of HTML, CSS and JavaScript in web development are: 1. HTML defines the web page structure, 2. CSS controls the web page style, and 3. JavaScript adds dynamic behavior. Together, they build the framework, aesthetics and interactivity of modern websites.

The future of HTML is full of infinite possibilities. 1) New features and standards will include more semantic tags and the popularity of WebComponents. 2) The web design trend will continue to develop towards responsive and accessible design. 3) Performance optimization will improve the user experience through responsive image loading and lazy loading technologies.

The roles of HTML, CSS and JavaScript in web development are: HTML is responsible for content structure, CSS is responsible for style, and JavaScript is responsible for dynamic behavior. 1. HTML defines the web page structure and content through tags to ensure semantics. 2. CSS controls the web page style through selectors and attributes to make it beautiful and easy to read. 3. JavaScript controls web page behavior through scripts to achieve dynamic and interactive functions.

HTMLisnotaprogramminglanguage;itisamarkuplanguage.1)HTMLstructuresandformatswebcontentusingtags.2)ItworkswithCSSforstylingandJavaScriptforinteractivity,enhancingwebdevelopment.

HTML is the cornerstone of building web page structure. 1. HTML defines the content structure and semantics, and uses, etc. tags. 2. Provide semantic markers, such as, etc., to improve SEO effect. 3. To realize user interaction through tags, pay attention to form verification. 4. Use advanced elements such as, combined with JavaScript to achieve dynamic effects. 5. Common errors include unclosed labels and unquoted attribute values, and verification tools are required. 6. Optimization strategies include reducing HTTP requests, compressing HTML, using semantic tags, etc.

HTML is a language used to build web pages, defining web page structure and content through tags and attributes. 1) HTML organizes document structure through tags, such as,. 2) The browser parses HTML to build the DOM and renders the web page. 3) New features of HTML5, such as, enhance multimedia functions. 4) Common errors include unclosed labels and unquoted attribute values. 5) Optimization suggestions include using semantic tags and reducing file size.


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

MantisBT
Mantis is an easy-to-deploy web-based defect tracking tool designed to aid in product defect tracking. It requires PHP, MySQL and a web server. Check out our demo and hosting services.

Dreamweaver Mac version
Visual web development tools

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

PhpStorm Mac version
The latest (2018.2.1) professional PHP integrated development tool

WebStorm Mac version
Useful JavaScript development tools