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

点击上下箭头,页码发生改变

时间:2018-01-11 22:33:38      阅读:160      评论:0      收藏:0      [点我收藏+]

标签:点击   com   html   anim   图片   lin   一个   blog   http   

技术分享图片

还是看图,channel的length为总页数,向上取整,点击上下箭头,分别向上下滚动,拒绝疯狂点击多次加载事件,细节看代码

    var clickLock = false;
            function calculateScrollTop (symbol) {
                var limit = 8;   //一页8个channel
                var itemHeight = 20;  //一个channel高20px
                var currentPage = $("#home_page").text() * 1; // home_page为当前页    注: *1是直接将text值转化为数字
                var allPages = Math.ceil(channelData.length / 8);  //向上取整 获取总页数
                var scrollTop = $(‘#line‘).scrollTop();  //获取滚动块的scrollTop值
                var flag = symbol ? currentPage < allPages : currentPage > 1;    // 根据传入参数判断点击的是上箭头还是下箭头   上箭头为0 下箭头为1
                if (flag) {
                    var changeTop = 0;
                    var size = (currentPage + (symbol ? 1 : -1)) * limit;
                    if (size > channelData.length) {
                        changeTop = (channelData.length - currentPage * limit) * itemHeight;
                    } else {
                        changeTop = limit * itemHeight;
                    }
                    if (changeTop != 0) {
                        clickLock = true;
                        $(‘#line‘).animate({"scrollTop": symbol ? scrollTop + changeTop: scrollTop - changeTop}, 200, ‘linear‘, function () {clickLock = false});
                        $("#home_page").html($("#home_page").text() * 1 + (symbol ? 1: -1));
                    }
                }
            }
            $("#triangle-down").click(function(){//点击三角箭头向下滚动一页(8个通道)
                if (clickLock) return;
                calculateScrollTop(true);
            });
            $("#triangle-up").click(function(){//点击三角箭头向上滚动一页(8个通道)
                if (clickLock) return;
                calculateScrollTop(false);
            });

点击上下箭头,页码发生改变

标签:点击   com   html   anim   图片   lin   一个   blog   http   

原文地址:https://www.cnblogs.com/fmixue/p/8270522.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有 京ICP备13008772号-2
迷上了代码!