码迷,mamicode.com
首页 > 其他好文 > 详细

全屏banner及全屏轮播

时间:2018-01-18 18:27:06      阅读:171      评论:0      收藏:0      [点我收藏+]

标签:remove   设置   center   enter   radius   cto   rip   函数   ott   

一、全屏banner

1、设置网页图片全屏banner

<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <title>Title</title>
    <style>
        * {
            margin: 0;
            padding: 0;
        }
        .pic {
            width: 100%;
            height: 600px;
            background: url("...") no-repeat center;
        }
    </style>
</head>
<body>
    <div class="banner">
        <div class="pic"></div>
    </div>
</body>
</html>

  二、全屏轮播

<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <title>全屏轮播模板</title>
    <style>
        html,body,head,span,button,div,title {
            margin: 0;
            padding: 0;
        }
        .cont {
            position: relative;
            height: 600px;
        }
        .list{
            position: relative;
        }
        .list div {
            width: 100%;
            height: 600px;
            position: absolute;
            opacity: 0;
            transition: 1s;  /*设置切换时间*/
        }
        .pic1 {
            background: url(img/lbt01.jpg) no-repeat center red;
        }
        .pic2 {
            background: url(img/lbt02.jpg) no-repeat center blue;
        }
        .pic3 {
            background: url(img/lbt03.jpg) no-repeat center yellow;
        }
        .pic4 {
            background: url(img/lbt04.jpg) no-repeat center green;
        }
        .pic5 {
            background: url(img/lbt05.jpg) no-repeat center pink;
        }
        .btns {
            position: absolute;
            z-index: 6;
            left: 50%;
            bottom: 80px;
            margin-left: -170px;
        }
        .btns span { 
            float: left;
            width: 60px;
            height: 5px;
            margin-right: 10px;
            background-color: rgba(255,255,255,0.3);
            border-radius: 5px;
        } 
        .buttons {
            width: 1180px;
            height: 600px;
            margin: 0 auto;
            position: relative;
        }
        .btn {  /*左右切换按钮样式*/
            position: absolute;
            top: 50%;
            margin-top: -26px;
            width: 32px;
            height: 52px;
            font-size: 30px;
            border-radius: 5px;
            z-index: 6;
            opacity: 0.5;
        }
        .btn-prev {
            left: 0;
        }
        .btn-next {
            right: 0;
        }
        .bgc {
            background-color: white !important;
        }
    </style>
</head>
<body>
    <div class="cont">
        <div class="list">
            <div class="pic1" data-index=0 style="opacity: 1; z-index: 2;"></div>
            <div class="pic2" data-index=1></div>
            <div class="pic3" data-index=2></div>
            <div class="pic4" data-index=3></div>
            <div class="pic5" data-index=4></div>
        </div>
        <div class="btns">
            <span class="bgc"></span>
            <span></span>
            <span></span>
            <span></span>
            <span></span>
        </div>
        <div class="buttons">
            <button class="btn btn-prev"> < </button>
            <button class="btn btn-next"> > </button>
        </div>
    </div>

    <script>
        var btn = document.getElementsByClassName("btn");
        var imgs = document.querySelectorAll(".list div");
        var btns = document.querySelectorAll(".btns span");
        var cont = document.getElementsByClassName("cont")[0];
        var indexes, timer = null;
        for(let i=0; i<btns.length; i++){
            btns[i].onmouseover = function(){  // 给所有下面的白色线条添加一个鼠标经过事件
                animate(i);
            }
        }

        btn[0].onclick = function(){  // 上一张按钮
            indexes = currentPage();
            if(indexes == 0) indexes=5;
                indexes--;
            animate(indexes);
        }

        btn[1].onclick = next;

        function next(){  // 下一张按钮
            indexes = currentPage();
            if(indexes == 4) indexes = -1;
                indexes++;
           animate(indexes);
        }

        function animate(i){  // 动画函数
            for(let j = 0; j<imgs.length; j++){
                imgs[j].style.opacity = 0;
                imgs[j].style.zIndex = 1;
                btns[j].classList.remove("bgc");
            }
            imgs[i].style.opacity = 1;
            imgs[i].style.zIndex = 2;
            btns[i].classList.add("bgc");
        }

        function currentPage() { // 返回当前页面
            for(var i = 0; i<imgs.length; i++){
                 if(imgs[i].style.zIndex == 2){
                    return imgs[i].dataset.index;
                 }
            }
        }

        timer = setInterval(next,3000); // 设置自动播放
        cont.onmousemove = function(){  // 鼠标移入时停止自动播放
            clearInterval(timer);
        }
        cont.onmouseout = function(){   // 鼠标移出时又开始播放
            timer = setInterval(next,3000);
        }
    </script>
</body>
</html>

  

全屏banner及全屏轮播

标签:remove   设置   center   enter   radius   cto   rip   函数   ott   

原文地址:https://www.cnblogs.com/litings/p/8306610.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!