全屏海报轮播css代码-如何使用JS+HTML+CSS来实现轮播效果
css如何实现无限轮播图动画(代码示例)

本篇文章给大家带来的内容是如何实现自动无限播放的轮播图动画效果,有一定的参考价值,有需要的朋友可以参考一下,希望对你们有所帮助。
在之前的文章【css如何实现图片的旋转展示效果】中介绍了手动无限轮播图的制作,本篇我们来看看自动无限轮播图动画的制作。下面我们就来看看动画效果是如何实现的。
1、设置动画的舞台
HTML与之前文章里的示例非常相似。我们要有一个动画发生的舞台(#stage),一个将会旋转的div容器和一系列图像:
<div id="stage">
<div id="rotator" style="-webkit-animation-name: rotator;">
<a href="1.jpg"><img src="1.jpg" width="140"></a>
<a href="2.jpg"><img src="2.jpg" width="140"></a>
<a href="3.jpg"><img src="3.jpg" width="140"></a>
<a href="4.jpg"><img src="4.jpg" width="140"></a>
<a href="5.jpg"><img src="5.jpg" width="140"></a>
<a href="6.jpg"><img src="6.jpg" width="140"></a>
<a href="7.jpg"><img src="7.jpg" width="140"></a>
<a href="8.jpg"><img src="8.jpg" width="140"></a>
</div>
</div>内联样式属性引用下面的动画 @keyframes。它需要内联而不是CSS,以便我们能够使用JavaScript停止和重新启动动画。
2、在3D空间中布置照片
CSS样式用于定位多张照片,首先围绕y轴旋转它们(垂直向上翻页),然后径向向外平移:
#stage {
margin: 2em auto 1em 50%;
height: 140px;
-webkit-perspective: 1200px;
-webkit-perspective-origin: 0 50%;
}
#rotator a {
position: absolute;
left: -81px;
}
#rotator a img {
padding: 10px;
border: 1px solid #ccc;
background: #fff;
-webkit-backface-visibility: hidden;
}
#rotator a:nth-of-type(1) img {
-webkit-transform: rotateY(-90deg) translateZ(300px);
}
#rotator a:nth-of-type(2) img {
-webkit-transform: rotateY(-60deg) translateZ(300px);
}
#rotator a:nth-of-type(3) img {
-webkit-transform: rotateY(-30deg) translateZ(300px);
}
#rotator a:nth-of-type(4) img {
-webkit-transform: translateZ(300px);
background: #000;
}
#rotator a:nth-of-type(5) img {
-webkit-transform: rotateY(30deg) translateZ(300px);
}
#rotator a:nth-of-type(6) img {
-webkit-transform: rotateY(60deg) translateZ(300px);
}
#rotator a:nth-of-type(n+7) { display: none; }照片设置-81px的值代表向左移动,使前向照片在旋转轴上居中。距离是图像宽度的一半(140px / 2)加上LHS图像填充(10px)和边框(1px)。
该阶段需要设置立体的动画,舞台从页面的中心开始,因此旋转 元素下的锚元素需要向后移动以使动画居中。
我们只开始准备六张照片, 左边三张,中间一张,右边两张。最左侧的照片(位置1)从左侧开始,因此仅在第一次旋转后才可见。
当照片旋转时,它会消失(显示:无),并且新照片会附加到左侧,准备从位置1旋转。在7和更高的位置可以有任意数量的照片。只有当它们移动到可见位置时,它们才会出现。
甚至可以在动画进行时使用Ajax加载新照片。
3、添加动画效果
正如我们之前尝试的那样,不是将照片轮旋转整整360度,而是我们实际做的只是旋转30度 (足以从一张照片到下一张照片):
@-webkit-keyframes rotator {
from { -webkit-transform: rotateY(0deg); }
to { -webkit-transform: rotateY(30deg); }
}
#rotator {
-webkit-transform-origin: 0 0;
-webkit-transform-style: preserve-3d;
-webkit-animation-timing-function: cubic-bezier(1, 0.2, 0.2, 1);
-webkit-animation-duration: 1s;
-webkit-animation-delay: 1s;
}
#rotator:hover {
-webkit-animation-play-state: paused;
}要使关键帧在其他浏览器中工作,请复制所有样式,替换-webkit- with -moz-和-ms-,如下面的示例代码块所示。
动画完成后,它会触发一个JavaScript事件,您可以在下一节中阅读该事件。事件处理程序沿着照片移动,以便在动画重置时,而不是回到初始状态,照片都围绕圆圈移动了一步。
为了更清楚地了解正在发生的事情,中心照片已在下面的演示中突出显示。在动画发生时,您将看到突出显示的节点旋转,然后重置回起始位置,但包含不同的照片。
4、 JavaScript添加动画控制器
我们在此示例中需要JavaScript来检测动画何时结束,以便协调通过车轮重置移动的照片。没有这个,轮子只会在前两张照片之间交替出现。
("DOMContentLoaded", function() {
var rotateComplete = function() {
= "";
(arr[-1], arr[0]);
setTimeout(function(el) {
= "rotator";
}, 0, target);
};
var target = ("rotator");
var arr = ("a");
("webkitAnimationEnd", rotateComplete, false);
}, false);对于每个WebKit样式和其他引用,存在Firefox(-moz-或Moz),Opera(-o-或O),甚至Internet Explorer(-ms-或ms)的替代品 - 我们必须忍受的混乱直到标准最终确定。
要在Safari,Chrome,Firefox,Opera和Internet Explorer 10中使用此功能,我们需要包含以下额外的设置:
var rotateComplete = function() {
with() {
webkitAnimationName = MozAnimationName = msAnimationName = "";
}
(arr[-1], arr[0]);
setTimeout(function(el) {
with() {
webkitAnimationName = MozAnimationName = msAnimationName = "rotator";
}
}, 0, target);
};
var target = ("rotator");
var arr = ("a");
("webkitAnimationEnd", rotateComplete, false);
("animationend", rotateComplete, false);
("MSAnimationEnd", rotateComplete, false);目前尚不清楚为何需要setTimeout。我们不需要它来设置延迟,因为使用CSS完成,但没有setTimeout(甚至0ms)动画无法重新触发。
5、效果展示
这只是横向的轮播,在之后的文章【css实现三面立体旋转无限轮播图动画】里会在本篇文章的基础上改进轮播方式,制作不一样的的轮播图动画。
如何使用JS+HTML+CSS来实现轮播效果

这篇文章主要为大家详细介绍了JS+HTML+CSS实现轮播效果,具有一定的参考价值,感兴趣的小伙伴们可以参考一下
本文实例为大家分享了Android九宫格图片展示的具体代码,供大家参考,具体内容如下
1.代码:
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<title>大轮播</title>
<link rel="stylesheet" type="text/css" href="CSS/"/>
<script src="JS/" type="text/javascript"></script>
</head>
<body>
<p id="container">
<p id="list" style="left: -1350px;">
<img src="image/banner_3.jpg"/>
<img src="image/banner_1.jpg"/>
<img src="image/banner_2.jpg"/>
<img src="image/banner_3.jpg">
<img src="image/banner_1.jpg"/></p>
<p id="buttons">
<span index="1"></span>
<span index="2"></span>
<span index="3"></span>
</p>
<a href="javascript:;" id="prev" class="arrow" style="font-size:100px; text-align:center;"><</a>
<a href="javascript:;" id="next" class="arrow" style="font-size:100px; text-align:center;">></a></p>
</body>
</html>2.CSS/代码:
body {
margin: 0px;
padding: 0px;
width: 1350px;
height: 618px;
}
a {
text-decoration: none;
}
#container {
width: 1350px;
height: 618px;
overflow: hidden;
position: relative;
border-top: 1px solid #ac6a0a;
}
#list {
width: 6750px;
height: 618px;
position: absolute;
z-index: 1;
}
#list img {
float: left;
width: 1350px;
height: 618px;
}
#buttons {
position: absolute;
height: 20px;
width: 60px;
z-index: 2;
bottom: 20px;
left: 50%;
}
#buttons span {
cursor: pointer;
float: left;
border: 1px solid #ad6a0a;
width: 10px;
height: 10px;
-webkit-border-radius: 50%;
-moz-border-radius: 50%;
border-radius: 50%;
margin-right: 5px;
}
#buttons .on {
background: orangered;
}
.arrow {
cursor: pointer;
display: none;
line-height: 100px;
text-align: center;
width: 40px;
height: 40px;
position: absolute;
z-index: 2;
top: 180px;
background-color: RGBA(0, 0, 0, 0);
color: #fff;
}
.arrow:hover {
background-color: RGBA(0, 0, 0, 0);
}
#container:hover .arrow {
display: block;
}
#prev {
left: 10px;
color: #ffffff;
}
#next {
right: 10px;
color: #ffffff;
}3.JS/代码:
= function () {
var container = ('container');
var list = ('list');
var buttons = ('buttons').getElementsByTagName('span');
var prev = ('prev');
var next = ('next');
var index = 1;
var len = 3;
var animated = false;
var interval = 3000;
var timer;
var size = 1350;
function animate(offset) {
if (offset == 0) {
return;
}
animated = true;
var time = 300;
var inteval = 10;
var speed = offset / (time / inteval);
("speed:" + speed);
var left = parseInt() + offset;
var go = function () {
if ((speed > 0 && parseInt() < left) || (speed < 0 && parseInt() > left)) {
= parseInt() + speed + 'px';
();
setTimeout(go, inteval);
} else {
= left + 'px';
if (left > -200) {
= -size * len + 'px';
}
if (left < ( -size * len)) {
= '-' + size + 'px';
}
animated = false;
("left:" + );
}
}
go();
}
function showButton() {
for (var i = 0; i < ; i++) {
if (buttons[i].className == 'on') {
buttons[i].className = '';
break;
}
}
buttons[index - 1].className = 'on';
}
function play() {
timer = setTimeout(function () {
();
play();
},
interval);
}
function stop() {
clearTimeout(timer);
}
= function () {
if (animated) {
return;
}
if (index == len) {
index = 1;
} else {
index += 1;
}
animate(-size);
showButton();
}
= function () {
if (animated) {
return;
}
if (index == 1) {
index = len;
} else {
index -= 1;
}
animate(size);
showButton();
}
for (var i = 0; i < ; i++) {
buttons[i].onclick = function () {
if (animated) {
return;
}
if ( == 'on') {
return;
}
var myIndex = parseInt(('index'));
var offset = -size * (myIndex - index);
animate(offset);
index = myIndex;
showButton();
}
}
= stop;
= play;
play();
};上面是我整理给大家的,希望今后会对大家有帮助。
相关文章:
在jQuery中如何使用EasyUI window窗口
在JS中如何实现十字坐标跟随鼠标效果
使用Angular4有关图片路径不安全的问题
在Webpack中如何构建Electron应用
怎么用html5+css3 实现图片轮播

1、首先我们创建一个简单的项目,如图所示包括html,css和img三个。
2、这里是html文件,引入css和html代码文件,如图所示。
3、这里是css文件代码,上面是div和图片显示的效果代码,后面是动画效果。
4、这里是事件,这里定义了四个时间段的状态,兼容了ie的。
5、如图所示这里是效果图,会根据时间轮播显示下一张图片 了。
-
果盘绘画图片大全简单创作方法快速制作技巧2024-01-02 16:57:54
-
小年插画图片创作方法快速制作技巧2024-01-02 16:57:20
-
小年绘画作品制作技巧2024-01-02 16:55:45
-
小年插画图片创作方法快速制作技巧2024-01-02 16:55:02
-
立春插画图片如何制作2024-01-02 16:54:19
-
立春插画图片创作方法快速制作技巧2024-01-02 16:53:32






扫描二维码添加客服微信
扫描二维码关注