博客
关于我
强烈建议你试试无所不能的chatGPT,快点击我
CSS3动画结合js实现3D轮播
阅读量:7081 次
发布时间:2019-06-28

本文共 11961 字,大约阅读时间需要 39 分钟。

昨天晚上有个同行提出要做一个旋转式的3D轮播图(下面统称banner图)。我就为了帮他看了一下相关的技术贴发现符合要求的很少,所以只能自己去动手写了。看到有人写了CSS3立体旋转动画的博客,我就想把这个动画拆分成几个模块来做一个banner效果可不可以?最后自己动手写了一下还是可以的。不过这个banner效果还是存在一些bug,因为不是急用所以我也没有修复。以后有空我会修复的。

html部分代码

1
2
3
4
5
6
7
8
9

css代码

*{
margin:0; padding: 0; } .container{
width: 210px; height:140px; position: relative; font-size: 32px; color: #FFFFFF; text-align: center; line-height: 90px; margin: 200px auto; perspective: 1000px; } .carouse{
transform-style:preserve-3d; } .carouse div{
display: block; position: absolute; width: 140px; height: 90px; border: 2px solid black; } .btn-group{
display: block; margin:100px auto; width: 240px; height: 30px; } .btn-group button{
width: 80px; height: 100%; } .carouse .pic1{
background:rgba(255,9,15,0.7); transform: rotateY(0deg) translateZ(210px); } .carouse .pic2{
background:rgba(100,9,100,0.7); transform: rotateY(40deg) translateZ(210px); } .carouse .pic3{
background:rgba(50,50,15,0.7); transform: rotateY(80deg) translateZ(210px); } .carouse .pic4{
background:rgba(150,100,200,0.7); transform: rotateY(120deg) translateZ(210px); } .carouse .pic5{
background:rgba(120,120,120,0.7); transform: rotateY(160deg) translateZ(210px); } .carouse .pic6{
background:rgba(110,9,250,0.7); transform: rotateY(200deg) translateZ(210px); } .carouse .pic7{
background:rgba(80,200,15,0.7); transform: rotateY(240deg) translateZ(210px); } .carouse .pic8{
background:rgba(180,150,100,0.7); transform: rotateY(280deg) translateZ(210px); } .carouse .pic9{
background:rgba(255,150,0,0.7); transform: rotateY(320deg) translateZ(210px); } /*=== 下一个动画 ===*/ @keyframes to-scroll1 {
0%{ transform: rotateY(0deg); } 100%{
transform: rotateY(-40deg); } } #carouse1{
animation: to-scroll1 2s ease both; /*animation-fill-mode: both;*/ } @keyframes to-scroll2 {
0%{ transform: rotateY(-40deg); } 100%{
transform: rotateY(-80deg); } } #carouse2{
animation: to-scroll2 2s ease both; /*animation-fill-mode: both;*/ } @keyframes to-scroll3 {
0%{ transform: rotateY(-80deg); } 100%{
transform: rotateY(-120deg); } } #carouse3{
animation: to-scroll3 2s ease both; /*animation-fill-mode: both;*/ } @keyframes to-scroll4 {
0%{ transform: rotateY(-120deg); } 100%{
transform: rotateY(-160deg); } } #carouse4{
animation: to-scroll4 2s ease both; /*animation-fill-mode: both;*/ } @keyframes to-scroll5 {
0%{ transform: rotateY(-160deg); } 100%{
transform: rotateY(-200deg); } } #carouse5{
animation: to-scroll5 2s ease both; /*animation-fill-mode: both;*/ } @keyframes to-scroll6 {
0%{ transform: rotateY(-200deg); } 100%{
transform: rotateY(-240deg); } } #carouse6{
animation: to-scroll6 2s ease both; /*animation-fill-mode: both;*/ } @keyframes to-scroll7 {
0%{ transform: rotateY(-240deg); } 100%{
transform: rotateY(-280deg); } } #carouse7{
animation: to-scroll7 2s ease both; /*animation-fill-mode: both;*/ } @keyframes to-scroll8 {
0%{ transform: rotateY(-280deg); } 100%{
transform: rotateY(-320deg); } } #carouse8{
animation: to-scroll8 2s ease both; /*animation-fill-mode: both;*/ } @keyframes to-scroll9 {
0%{ transform: rotateY(-320deg); } 100%{
transform: rotateY(-360deg); } } #carouse9{
animation: to-scroll9 2s ease both; /*animation-fill-mode: both;*/ } /* @keyframes to-scroll10 { 0%{ transform: rotateY(-360deg); } 100%{ transform: rotateY(-400deg); } } #carouse10{ animation: to-scroll10 2s ease both; /*animation-fill-mode: both;*/ }*/ /* === 上一个动画 ===*/ @keyframes to-scroll21 {
0%{ transform: rotateY(-40deg); } 100%{
transform: rotateY(0deg); } } #carouse21{
animation: to-scroll21 2s ease both; /*animation-fill-mode: both;*/ } @keyframes to-scroll22 {
0%{ transform: rotateY(-80deg); } 100%{
transform: rotateY(-40deg); } } #carouse22{
animation: to-scroll22 2s ease both; /*animation-fill-mode: both;*/ } @keyframes to-scroll23 {
0%{ transform: rotateY(-120deg); } 100%{
transform: rotateY(-80deg); } } #carouse23{
animation: to-scroll23 2s ease both; /*animation-fill-mode: both;*/ } @keyframes to-scroll24 {
0%{ transform: rotateY(-160deg); } 100%{
transform: rotateY(-120deg); } } #carouse24{
animation: to-scroll24 2s ease both; /*animation-fill-mode: both;*/ } @keyframes to-scroll25 {
0%{ transform: rotateY(-200deg); } 100%{
transform: rotateY(-160deg); } } #carouse25{
animation: to-scroll25 2s ease both; /*animation-fill-mode: both;*/ } @keyframes to-scroll26 {
0%{ transform: rotateY(-240deg); } 100%{
transform: rotateY(-200deg); } } #carouse26{
animation: to-scroll26 2s ease both; /*animation-fill-mode: both;*/ } @keyframes to-scroll27 {
0%{ transform: rotateY(-280deg); } 100%{
transform: rotateY(-240deg); } } #carouse27{
animation: to-scroll27 2s ease both; /*animation-fill-mode: both;*/ } @keyframes to-scroll28 {
0%{ transform: rotateY(-320deg); } 100%{
transform: rotateY(-280deg); } } #carouse28{
animation: to-scroll28 2s ease both; /*animation-fill-mode: both;*/ } @keyframes to-scroll29 {
0%{ transform: rotateY(-360deg); } 100%{
transform: rotateY(-320deg); } } #carouse29{
animation: to-scroll29 2s ease both; /*animation-fill-mode: both;*/ } @keyframes to-scroll30 {
0%{ transform: rotateY(-400deg); } 100%{
transform: rotateY(-360deg); } } #carouse30{
animation: to-scrol30 2s ease both; /*animation-fill-mode: both;*/ }

js代码

var prevBut = document.getElementById("prev");    var nextBut = document.getElementById("next");    var carouse = document.getElementsByClassName("carouse")    var state = 1;  //id的变化状态    prevBut.addEventListener("click",function() {        prev();    }) ;    nextBut.addEventListener("click",function() {        next();    }) ;    function prev(){        if( state == 1||state == 21){            state = 29;            carouse.item(0).id = 'carouse'+state;        }else if(state == 2||state == 22){            state = 21;            carouse.item(0).id = 'carouse'+state;        }else if(state == 3 || state == 23){            state = 22;            carouse.item(0).id = 'carouse'+state;        }else if(state == 4 || state == 24){            state = 23;            carouse.item(0).id = 'carouse'+state;        }else if(state == 5||state == 25){            state = 24;            carouse.item(0).id = 'carouse'+state;        }else if(state == 6 || state == 26){            state = 25;            carouse.item(0).id = 'carouse'+state;        }else if(state == 7 || state == 27){            state = 26;            carouse.item(0).id = 'carouse'+state;        }else if(state == 8||state == 28){            state = 27;            carouse.item(0).id = 'carouse'+state;        }else if(state == 9 || state == 29){            state = 28;            carouse.item(0).id = 'carouse'+state;        }else if(state == 10 || state == 30){            state = 29;            carouse.item(0).id = 'carouse'+state;        }    }    function next() {        if( state == 1||state == 21){            state = 1;            carouse.item(0).id = 'carouse'+state;            state++;        }else if(state == 2||state == 22){            state = 2;            carouse.item(0).id = 'carouse'+state;            state++;        }else if(state == 3 || state == 23){            state = 3;            carouse.item(0).id = 'carouse'+state;            state++;        }else if(state == 4 || state == 24){            state = 4;            carouse.item(0).id = 'carouse'+state;            state++;        }else if(state == 5||state == 25){            state = 5;            carouse.item(0).id = 'carouse'+state;            state++;        }else if(state == 6 || state == 26){            state = 6;            carouse.item(0).id = 'carouse'+state;            state++;        }else if(state == 7 || state == 27){            state = 7;            carouse.item(0).id = 'carouse'+state;            state++;        }else if(state == 8||state == 28){            state = 8;            carouse.item(0).id = 'carouse'+state;            state++;        }else if(state == 9 || state == 29){            state = 9;            carouse.item(0).id = 'carouse'+state;            state++;        }else if(state == 10 || state == 30){            state = 1;            carouse.item(0).id = 'carouse'+state;        }    }

效果图

 

  

转载于:https://www.cnblogs.com/nurdun/p/6789700.html

你可能感兴趣的文章
聚焦理论—《可以量化的管理学》
查看>>
如何给网站配置SSL证书(https)
查看>>
学习导航
查看>>
独家 | 如何改善你的训练数据集?(附案例)
查看>>
Linux学习(十):查看文件系统(dumpe2fs)
查看>>
用SQL命令查看Mysql数据库大小
查看>>
阿里云MaxCompute技术共享计划 首波技术公开课干货集锦
查看>>
系统思考负反馈之西蒙的组织均衡分析
查看>>
C# winform嵌入unity3D
查看>>
Ubuntu 16.04安装RabbitVCS替代TortoiseSVN/TortoiseGit
查看>>
Linux下的/etc/crontab文件和crontab -e命令区别及Crontab命令详解(转)
查看>>
软银展示5G应用,用超高速通信技术控制机器人实时“守门”
查看>>
OpenJDK与JDK的区别分析
查看>>
我的大学四年
查看>>
OpenID Connect 协议入门指南
查看>>
MySql基本数据类型(转)
查看>>
Atom飞行手册翻译: 4.4 Atom中的序列化
查看>>
AMD楚含进:为什么说VR正在颠覆传统的电竞?
查看>>
人工智能仍然只是一个梦:浅谈“深度学习”目前存在着的若干问题
查看>>
远程访问传感器获取数据并传入数据库
查看>>