简单的幻灯片实现

1、第一种方法
<!DOCTYPE html>
<html>
<head>
    <title></title>
    <style>
    img {
      display: none;
      width: 100px;
      height: 100px;
    }
 
    input:checked + img {
      display: block;
    }
 
    input {
      position: absolute;
      left: -9999px;
    }
 
    label {
      cursor: pointer;
    }
    </style>
</head>
<body>
    <div id="cont">
        <input id="img1" name="img" type="radio" checked="checked">
        <img src="1.jpg" width="100" height="100">
        <input type="radio" name="img" id="img2">
        <img src="2.jpg" width="100" height="100">
    </div>
    <div id="nav">
        <label for="img1">第一张</label>
        <label for="img2">第二张</label>
    </div>
</body>
</html>
 <!--兼容性: IE8以及IE8以下的浏览器不兼容,只显示文字,不显示图片-->


    <!--以上代码实现使用到的技术:
        除了设置相应的CSS样式,有两点值得注意:
            1.设置按钮的位置(绝对定位) ,left:-9999px用来隐藏按钮;
            2.<label>标签中的for属性与input标签中的id关联,然后根据input的checked的状态显示或隐藏图片,来达到显示幻灯片效果的目的。
    -->


2、第二种方法

<!DOCTYPE html>
<html lang="zh-CN">
<head>
    <meta charset="UTF-8">
    <title>css3 实现幻灯片效果</title>
    <style type="text/css">
        .huanDengPic {
            width: 600px;
            height: 600px;
            margin: 50px auto 0;
            overflow: hidden;
            box-shadow:  0 0 5px rgba(0,0,0,1);   /*CSS3 box-shadow属性,里面的值的设置s可以去网上查*/
            background-size: cover; 
            background-position: center;
            -webkit-animation-name: "loops"; /*检索或设置对象所应用的动画名称*/
            -webkit-animation-duration: 10s; /*检索或设置对象动画的持续时间*/
            -webkit-animation-iteration-count: infinite;  /*检索或设置对象动画的循环次数,此处的"infinite"为无限循环的意思*/
        }

        @-webkit-keyframes "loops" {  /*动画名称和上面设置的动画名称一样*/
            /*下面是动画过程*/
            0% {
                background: url(1.jpg) no-repeat;
            }

            50% {
                background: url(2.jpg) no-repeat;
            }

            100% {
                background: url(3.jpg) no-repeat;
            }
        }

    </style>
</head>
<body>
    <div class="huanDengPic"></div>
</body>
</html>


  • 0
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

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

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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值