CSS3实现3D效果的图片墙_html/css_WEB-ITnose
先来看一下效果:http://1.huizit1.applinzi.com/CSS/transform_3D/img_3D.html
布局结构:
<div class="container"> <img src="/static/imghw/default1.png" data-src="../Img/1.jpg" class="lazy" alt="CSS3实现3D效果的图片墙_html/css_WEB-ITnose" > <img src="/static/imghw/default1.png" data-src="../Img/2.jpg" class="lazy" alt="CSS3实现3D效果的图片墙_html/css_WEB-ITnose" > <img src="/static/imghw/default1.png" data-src="../Img/3.jpg" class="lazy" alt="CSS3实现3D效果的图片墙_html/css_WEB-ITnose" > <img src="/static/imghw/default1.png" data-src="../Img/4.jpg" class="lazy" alt="CSS3实现3D效果的图片墙_html/css_WEB-ITnose" > <img src="/static/imghw/default1.png" data-src="../Img/5.jpg" class="lazy" alt="CSS3实现3D效果的图片墙_html/css_WEB-ITnose" > <img src="/static/imghw/default1.png" data-src="../Img/6.jpg" class="lazy" alt="CSS3实现3D效果的图片墙_html/css_WEB-ITnose" > <img src="/static/imghw/default1.png" data-src="../Img/7.jpg" class="lazy" alt="CSS3实现3D效果的图片墙_html/css_WEB-ITnose" > <img src="/static/imghw/default1.png" data-src="../Img/8.jpg" class="lazy" alt="CSS3实现3D效果的图片墙_html/css_WEB-ITnose" > <img src="/static/imghw/default1.png" data-src="../Img/9.jpg" class="lazy" alt="CSS3实现3D效果的图片墙_html/css_WEB-ITnose" > <img src="/static/imghw/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/imghw/default1.png" data-src="../Img/1.jpg" class="lazy" alt="CSS3实现3D效果的图片墙_html/css_WEB-ITnose" >74 <img src="/static/imghw/default1.png" data-src="../Img/2.jpg" class="lazy" alt="CSS3实现3D效果的图片墙_html/css_WEB-ITnose" >75 <img src="/static/imghw/default1.png" data-src="../Img/3.jpg" class="lazy" alt="CSS3实现3D效果的图片墙_html/css_WEB-ITnose" >76 <img src="/static/imghw/default1.png" data-src="../Img/4.jpg" class="lazy" alt="CSS3实现3D效果的图片墙_html/css_WEB-ITnose" >77 <img src="/static/imghw/default1.png" data-src="../Img/5.jpg" class="lazy" alt="CSS3实现3D效果的图片墙_html/css_WEB-ITnose" >78 <img src="/static/imghw/default1.png" data-src="../Img/6.jpg" class="lazy" alt="CSS3实现3D效果的图片墙_html/css_WEB-ITnose" >79 <img src="/static/imghw/default1.png" data-src="../Img/7.jpg" class="lazy" alt="CSS3实现3D效果的图片墙_html/css_WEB-ITnose" >80 <img src="/static/imghw/default1.png" data-src="../Img/8.jpg" class="lazy" alt="CSS3实现3D效果的图片墙_html/css_WEB-ITnose" >81 <img src="/static/imghw/default1.png" data-src="../Img/9.jpg" class="lazy" alt="CSS3实现3D效果的图片墙_html/css_WEB-ITnose" >82 <img src="/static/imghw/default1.png" data-src="../Img/10.jpg" class="lazy" alt="CSS3实现3D效果的图片墙_html/css_WEB-ITnose" >83 </div>84 </body>85 </html>

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



HTML is suitable for beginners because it is simple and easy to learn and can quickly see results. 1) The learning curve of HTML is smooth and easy to get started. 2) Just master the basic tags to start creating web pages. 3) High flexibility and can be used in combination with CSS and JavaScript. 4) Rich learning resources and modern tools support the learning process.

The article discusses the HTML <progress> element, its purpose, styling, and differences from the <meter> element. The main focus is on using <progress> for task completion and <meter> for stati

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.

The article discusses the HTML <datalist> element, which enhances forms by providing autocomplete suggestions, improving user experience and reducing errors.Character count: 159

The article discusses the HTML <meter> element, used for displaying scalar or fractional values within a range, and its common applications in web development. It differentiates <meter> from <progress> and ex

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

AnexampleofastartingtaginHTMLis,whichbeginsaparagraph.StartingtagsareessentialinHTMLastheyinitiateelements,definetheirtypes,andarecrucialforstructuringwebpagesandconstructingtheDOM.

GiteePages static website deployment failed: 404 error troubleshooting and resolution when using Gitee...
