• 前端开发 —— 图片轮播


    今日一言:
    受身无间者永远不死,寿长乃无间地狱中之大劫。
    ——《涅盘经》

    前端开发 —— 图片轮播


    HTML

    <div class="content">
        <div class="img_box">
            <ul>
                <li><img src="./img/1.jpeg" style=" 640px;height: 480px" /></li>
                <li><img src="./img/2.jpeg" style=" 640px;height: 480px"/></li>
                <li><img src="./img/3.jpeg" style=" 640px;height: 480px"/></li>
                <li><img src="./img/4.jpeg" style=" 640px;height: 480px"/></li>
                <li><img src="./img/5.jpeg" style=" 640px;height: 480px"/></li>
            </ul>
            <p>
                <span class="leftBtn">&lt;</span>
                <span class="rightBtn">&gt;</span>
            </p>
            <div class="bar" style=" 640px;height:5px;background-color: #FFFFFF"></div>
        </div>
    </div>

    CSS

    body{
        background-color#212121;
    }

    li{
        list-style-type: none;
    }

    ul {
        width640px;
        height480px;

        padding0;
        display: flex;
    }

    .img_box{
        width640px;
        height480px;
        position: absolute;
        left50%;
        top50%;
        margin-left: -320px;
        margin-top: -240px;
        overflow: hidden;
    }

    p{
        position: absolute;
        width640px;
        height70px;
        top50%;
        left50%;
        margin-left: -320px;
        margin-top: -35px;
        display: flex;
        justify-content: space-between;
    }

    .rightBtn{
        -webkit-touch-callout: none;
        -webkit-user-select: none;
        -khtml-user-select: none;
        -moz-user-select: none;
        -ms-user-select: none;
        user-select: none;
        display: inline-block;
        font-size50px;
        width70px;
        height70px;
        border-radius9px;
        text-align: center;
        margin-right5px
        color#fff;
        background-colorrgba(0,0,0,0.5);
        cursor: pointer;
    }

    .leftBtn{
        -webkit-touch-callout: none;
        -webkit-user-select: none;
        -khtml-user-select: none;
        -moz-user-select: none;
        -ms-user-select: none;
        user-select: none;
        user-select:none;
        display: inline-block;
        font-size50px;
        width70px;
        height70px;
        border-radius9px;
        text-align: center;
        color#fff;
        margin-left5px;
        background-colorrgba(0,0,0,0.5);
        cursor: pointer;
    }

    .bar{
        position: absolute;
        bottom0;
    }

    JavaScript

    var cureent = 0;
    var time = $("img").width();
    var timer;
    var leftBtn = $(".leftBtn");
    var rightBtn = $(".rightBtn");

    function show(status){
        if( status == 1 ){
            timer = setInterval(function(){
                time--;
                if( time < 0 ){
                    Tright();
                    time = box.width();
                }
                $(".bar").width($("img").width()-time+"px");
            },10);
        } else {
            clearInterval(timer);
            time = $("img").width();
        }
    }

    show(1);

    $(".img_box").hover(function(){
        leftBtn.fadeIn(30);
        rightBtn.fadeIn(30);
    });

    $(".img_box").mouseleave(function(){
        leftBtn.fadeOut(30);
        rightBtn.fadeOut(30);
    });

    function Tleft(){
        show(0);
        cureent--;
        if( cureent < 0 ) cureent = 4;
        $("ul").animate({marginLeft-640 * cureent + "px"});
        show(1);
    }

    function Tright(){
        show(0);
        cureent++;
        if( cureent >= 5 ) cureent = 0;
        $("ul").animate({marginLeft-640 * cureent +"px"});
        show(1);
    }

    leftBtn.click(function(){
        Tleft();
    });

    rightBtn.click(function(){
        Tright();
    });

  • 相关阅读:
    shell 编程 如何实现 比较两个整数的大小
    从Mysql某一表中随机读取n条数据的SQL查询语句
    AS3中UTF8、GB2312、BIG5、GBK编码转换类
    Google Map API V3 离线版
    linux下解压命令大全
    PHP 5.3无法安装Memcached解决方案
    根据淘宝商品 num_iid 批量生成淘宝客链接的 PHP 函数
    Linux curl使用简单介绍
    TCP/IP UDP用户数据报协议 运输层
    TCP/IP 应用层
  • 原文地址:https://www.cnblogs.com/rcklos/p/12977275.html
Copyright © 2020-2023  润新知