使用css3的动画制作一个简易的轮播图

前端页面中的轮播图制作方法有很多种,之前都是用js来写,这次学到了css3动画,发现了用css实现的更加简单的办法,来制作一个轮播图,原理则是采用css3动画作为主要载体,主要是移动盒子的浮动尺寸,来达到移动效果.

<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>3d</title>
    <style>
#parn{

    width: 1000px ;
    height: 500px;
    overflow: hidden; 
    /* 将超出范围的元素隐藏起来,这样每次就只显示一个与盒子大小相等的元素 */
}
#son{
    width: 2000px; 
    /* 子盒子中放的大小是与父盒子的倍数关系 */

    animation: myname 10s 10;
    /* 后面的参数:设置的动画名称 时长 播放次数 */

}
#son>img{
    float: left;
    width: 1000px;
    height: 500px;
}
@keyframes myname {
    50% {margin-left: -1000px;}
  /* 这里我只放了2张图片,所以,只要做50%做一次动作即可 */

}
    </style>
</head>
<body>
    <div id="parn">
<div id="son">
   
    <img src="./1.jpg" alt="">
    <img src=".//R-C.jpg" alt="">
</div>


    </div>



</body>
</html>

  • 0
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 打赏
    打赏
  • 0
    评论
好的,以下是一个简单的 HTML 和 CSS 3D 轮播图片示例,其中包含四张图片 : ```html <!DOCTYPE html> <html> <head> <title>3D轮播图片</title> <style> body { margin: 0; padding: 0; overflow: hidden; } .container { position: relative; width: 100vw; height: 100vh; perspective: 1000px; transform-style: preserve-3d; } .item { position: absolute; top: 0; left: 0; width: 100%; height: 100%; display: flex; align-items: center; justify-content: center; font-size: 5em; color: #fff; background-color: #333; transform-style: preserve-3d; transition: transform 1s; } .item:nth-child(1) { transform: rotateY(0deg) translateZ(500px); } .item:nth-child(2) { transform: rotateY(90deg) translateZ(500px); } .item:nth-child(3) { transform: rotateY(180deg) translateZ(500px); } .item:nth-child(4) { transform: rotateY(270deg) translateZ(500px); } .container:hover .item:nth-child(1) { transform: rotateY(-90deg) translateZ(500px); } .container:hover .item:nth-child(2) { transform: rotateY(0deg) translateZ(500px); } .container:hover .item:nth-child(3) { transform: rotateY(90deg) translateZ(500px); } .container:hover .item:nth-child(4) { transform: rotateY(180deg) translateZ(500px); } </style> </head> <body> <div class="container"> <div class="item">1</div> <div class="item">2</div> <div class="item">3</div> <div class="item">4</div> </div> </body> </html> ``` 在这个示例中,我们使用了 CSS 的 3D 变换来实现轮播图片的效果。每个图片元素都有不同的旋转角度和 3D 位移量。鼠标悬停在容器上时,通过修改旋转角度来实现图片的切换效果。 您可以将每个图片元素的内容替换成自己的图片链接或其他内容。如果您需要添加更多的图片,可以复制 `.item` 元素并根据需要修改旋转角度和位移量。

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包

打赏作者

吴爃

你的鼓励将是我创作的最大动力

¥1 ¥2 ¥4 ¥6 ¥10 ¥20
扫码支付:¥1
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值