• 前端实现左右翻页功能Demo


    <!DOCTYPE html>
    <html lang="en">
    <head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <meta http-equiv="X-UA-Compatible" content="ie=edge">
    <title>Document</title>
    <style>
    section {
    600px;
    height: 400px;
    margin: auto;
    overflow: hidden;
    }
    .container {
    2400px;
    height: 100%;
    /* 去掉子元素中的间隙 */
    background-color: aquamarine;
    font-size: 0;
    }
    .container div {
    display: inline-block;
    600px;
    height: calc(100% - 60px);
    font-size: 20px;
    }
    .btn_next,
    .btn_pre {
    150px;
    height: 40px;
    line-height: 40px;
    text-align: center;
    border-radius: 5px;
    border: 1px solid yellowgreen;
    margin-bottom: 20px;
    cursor: pointer;
    }
    </style>
    </head>
    <body>
    <section>
    <div class="btn_next">请点击我向后翻页</div>
    <div class="btn_pre">请点击我向前翻页</div>
    <div class="container">
    <div>元素一</div>
    <div>元素二</div>
    <div>元素三</div>
    <div>元素四</div>
    </div>
    </section>
    <script src="http://libs.baidu.com/jquery/2.1.4/jquery.min.js"></script>
    <script>
    let margin = 0;
    $('.btn_next').on('click',function() {
    handleClickNext();
    })
    $('.btn_pre').on('click',function() {
    handleClickPre();
    })
     
    function handleClickNext() {
    if(margin >= -1200) {
    margin = margin - 600;
    $('.container').css({
    transform: 'translateX('+ margin +'px)',
    'transition': 'transform 1s'
    })
    } else {
    alert('已经是最后一页了')
    }
    }
    function handleClickPre() {
    if(margin <= -600) {
    margin = margin + 600;
    $('.container').css({
    transform: 'translateX('+ margin +'px)',
    'transition': 'transform 1s'
    })
    } else {
    alert('已经是第一页了')
    }
    }
    </script>
    </body>
    </html>
  • 相关阅读:
    codeforces 671B Robin Hood 二分
    HDU 4009 Transfer water 最小树形图
    HDU 2121 Ice_cream’s world II 最小树形图
    UVA1395 Slim Span(枚举最小生成树)
    ZOJ 1107FatMouse and Cheese(BFS)
    POJ2239 Selecting Courses(二分图最大匹配)
    UVA 11419SAM I AM(输出 最小覆盖点 )
    POJ 3678 Katu Puzzle(强连通 法)
    POJ3207Ikki's Story IV
    POJ1236Network of Schools(强连通分量 + 缩点)
  • 原文地址:https://www.cnblogs.com/chun-chun/p/14189053.html
Copyright © 2020-2023  润新知