css animation实现图片切换效果

本文介绍了一种使用CSS动画和Sass循环语句创建动态图片轮播的方法,通过不同动画时长实现图片无限切换效果,同时提出了解决图片数量自适应的方案。
<!DOCTYPE html>
<html>

<head>
    <meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
    <meta name="viewport" content="initial-scale=1.0, user-scalable=no" />
    <style type="text/css">
        body,
        html {
            width: 100%;
            height: 100%;
            margin: 0;
            font-family: "微软雅黑";
        }
        
        #center {
            display: flex;
            justify-content: center;
            align-items: center;
        }
        
        .iamge2,
        .iamge3,
        .iamge4 {
            opacity: 0;
            position: absolute;
            top: 0px;
            left: 0px;
            height: 100%;
            width: 100%;
        }
        
        @keyframes cf4FadeInOut {
            0% {
                opacity: 1;
            }
            100% {
                opacity: 0;
            }
        }
        
        #cf4a {
            position: relative;
            height: 280px;
            width: 450px;
            margin: 0 auto;
            overflow-x: hidden;
            border: 1px solid #ccc;
            background: #ccc
        }
        
        .iamge1 {
            animation-name: cf4FadeInOut;
            animation-timing-function: ease-in-out;
            animation-iteration-count: infinite;
            animation-duration: 1s;
            animation-direction: alternate;
        }
        
        .iamge2 {
            animation-name: cf4FadeInOut;
            animation-timing-function: ease-in-out;
            animation-iteration-count: infinite;
            animation-duration: 2.5s;
            animation-direction: alternate;
        }
        
        .iamge3 {
            animation-name: cf4FadeInOut;
            animation-timing-function: ease-in-out;
            animation-iteration-count: infinite;
            animation-duration: 4.5s;
            animation-direction: alternate;
        }
        
        .iamge4 {
            animation-name: cf4FadeInOut;
            animation-timing-function: ease-in-out;
            animation-iteration-count: infinite;
            animation-duration: 6s;
            animation-direction: alternate;
        }
    </style>
    <script type="text/javascript" src="./jquery-3.3.1.min.js"></script>
    <title>animate demo</title>
</head>

<body id="center">
    <div id="cf4a">
        <img class="iamge1" src="./images/1.jpg" />
        <img class="iamge2" src="./images/2.jpg" />
        <img class="iamge3" src="./images/3.jpg" />
        <img class="iamge4" src="./images/4.jpg" />
    </div>
</body>

</html>
  1. 这只是静态样式,其中有很多重复的,可以结合sass将公共的样式提取出来
  2. 对于动态的样式,可以结合sass的循环语句进行循环生成css
  3. 推荐在循环遍历照片的时候添加对应的css以便达到自适应图片数量的切换效果
<head> <meta charset="UTF-8" /> <meta http-equiv="X-UA-Compatible" content="IE=edge">  <title>37种效果html5 css3图片幻灯片切换特效</title> <meta name="viewport" content="width=device-width, initial-scale=1">  <link rel="stylesheet" type="text/css" href="css/normalize.css?3.1.64" /> <link rel="stylesheet" type="text/css" href="css/demo.css?3.1.64" /> <link rel="stylesheet" type="text/css" href="css/component.css?3.1.64" /> <link rel="stylesheet" type="text/css" href="css/fxsmall.css?3.1.64" /> [removed][removed] </head> <body>[removed][removed] <div class="container"> <header class="codrops-header"> <nav class="codrops-demos"> <a >Small Component</a> <a >Full Width</a> <a >Transparent</a> </nav> </header> <section> <div class="custom-select"> <select id="fxselect" name="fxselect"> <option value="-1" selected>选择一种效果...</option> <option value="fxCorner">Corner scale</option> <option value="fxVScale">Vertical scale</option> <option value="fxFall">Fall</option> <option value="fxFPulse">Forward pulse</option> <option value="fxRPulse">Rotate pulse</option> <option value="fxHearbeat">Hearbeat</option> <option value="fxCoverflow">Coverflow</option> <option value="fxRotateSoftly">Rotate me softly</option> <option value="fxDeal">Deal &#39;em</option> <option value="fxFerris">Ferris wheel</option> <option value="fxShinkansen">Shinkansen</option> <option value="fxSnake">Snake</option> <option value="fxShuffle">Shuffle</option> <option value="fxPhotoBrowse">Photo Browse</option> <option value="fxSlideBehind">Slide Behind</option> <option value="fxVacuum">Vacuum</option> <option value="fxHurl">Hurl it</option> </select> </div> 一款基于jquery html5 css3实现37种不同切换效果图片幻灯片切换特效,html5 css3网页焦点图轮播代码
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

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

余额充值