评论:移动端字母索引列表  [查看原文]

所属分类:其他,APP模板-杂项,其他

 12774  189  2
当前第1页 / 共1页
    ruanlu1
    2022/3/3 17:32:53

    该插件默认是监控 html/body 的滚动,当需要指定参照元素时,可以在配置元素中增加一个 .content属性,然后增加判断条件:  if 

    (_self.config.content) {
        //list距离顶部的距离,然后减去
        var listTop = $(_self.config.el).offset().top;
        currentTop = currentTop - listTop;
        console.log(listTop);
        $(_self.config.content).scrollTo({
            toT: currentTop,
            callback: () => {
                $('#hhb_prompt').remove();
            }
        });
    }

    以及

    let throttled = _self.throttle(function() {
        let currentTop = document.documentElement.scrollTop || document.body.scrollTop;
        if ($(_self.config.content)) {
            currentTop = $(_self.config.content).scrollTop() + topArr[0];
        }
        let currentIndex = _self.getArrIndex(topArr, currentTop);
        $(_self.config.elNav).find('li').removeClass('active').eq(currentIndex).addClass('active');
    }, 300);
        ruanlu1
        2022/3/3 17:36:11

        配置

        init(options) {
            //默认配置
            this.config = $.extend(true, {}, {
                content: '.indexed-content', //选填,滚动条主体,相对于哪一个主体页面滚动,默认为当前页面
                el: '.indexed-list', //主列表DOM [选填,默认值:.indexed-list]
                elNav: '.indexed-nav', //右侧列表DOM [选填,默认值:.indexed-nav]
                datas: [] //自定义的数据 [必填,默认为空数组]
            }, options);
        
            this.autoCreate();
        }
    回复

讨论这个项目(2)回答他人问题或分享插件使用方法奖励jQ币 评论用户自律公约

取消回复