• Django打造大型企业官网(四)


    4.3.轮播图布局和样式

    templates/news/index.html

    <div class="news-wrapper">
                    <div class="banner-group">
                        <ul class="banner-ul">
                            <li>
                                <a href="">
                                    <img src="https://static-image.xfz.cn/1523588994_243.jpg" alt="">
                                </a>
                            </li>
                            <li>
                                <a href="">
                                    <img src="https://static-image.xfz.cn/1521444982_469.jpg" alt="">
                                </a>
                            </li>
                            <li>
                                <a href="">
                                    <img src="https://static-image.xfz.cn/1521444982_469.jpg" alt="">
                                </a>
                            </li>
                            <li>
                                <a href="">
                                    <img src="https://static-image.xfz.cn/1523588994_243.jpg" alt="">
                                </a>
                            </li>
                        </ul>
                    </div>
                </div>

    src/css/index.scss

            .news-wrapper{
                float: left;
                width: 798px;
                height: 500px;
                background: #fff;
    
                .banner-group{
                    width: 100%;
                    height: 202px;
                    background: #0a275a;
    
                    .banner-ul{
                        overflow: hidden;
                        width: 798px * 4;
    
                        li{
                            float: left;
                            width: 798px;
                            height: 202px;
    
                            img{
                                width: 798px;
                                height: 202px;
                            }
                        }
                    }
                }
            }
    
            .sidebar-wrapper{
                float: right;
                width: 356px;
                height: 500px;
                background: darkseagreen;
            }
        }
    }

    4.4.实现一次轮播

    templates/news/index.html

    <script src="../../dist/js/jquery-3.3.1.min.js" ></script>
    <script src="../../dist/js/index.min.js" ></script>
    
    
    <ul class="banner-ul" id="banner-ul">

    src/js/index.js

    //初始化
    function Banner() {
    
    };
    
    //添加一个run方法
    Banner.prototype.run = function () {
        var bannerUL = $("#banner-ul");
        //500是间隔时间0.5s
        bannerUL.animate({"left":-798},500)
    };
    
    //页面加载完成后执行。创建一个对象,运行方法
    $(function () {
        var banner = new Banner();
        banner.run()
    });

    4.5.实现自动轮播

    src/js/index.js

    //添加一个run方法
    Banner.prototype.run = function () {
        var bannerUL = $("#banner-ul");
        var index = 0;
        setInterval(function () {
            if(index >= 3){
                index = 0
            }else{
                index++;
            }
            bannerUL.animate({"left":-798*index},500);
        },2000);
    
    };
     
     
     
  • 相关阅读:
    【BZOJ4868】期末考试 [三分][贪心]
    【BZOJ4880】排名的战争 [暴力]
    【BZOJ1449&&2895】球队预算 [费用流]
    【BZOJ1221】【HNOI2001】软件开发 [费用流]
    【BZOJ4837】LRU算法 [模拟]
    Leetcode题解(30)
    Leetcode题解(29)
    Leetcode题解(28)
    Leetcode题解(27)
    Leetcode题解(26)
  • 原文地址:https://www.cnblogs.com/gaidy/p/12106997.html
Copyright © 2020-2023  润新知