美文网首页
js 分类点击置顶

js 分类点击置顶

作者: 莫奈的有趣灵魂 | 来源:发表于2019-12-02 15:25 被阅读0次
 mounted() {
            window.addEventListener('scroll', this.scrollToTop);
        },
        destroyed() {
            window.removeEventListener('scroll', this.scrollToTop);
        },
methods(){
        scrollToTop() {
                var scrollTop = window.pageYOffset || document.documentElement.scrollTop || document.body.scrollTop;
            },
//点击函数
change: function (index) {
                this.current = index;
                //获取热门分类高度
                vuedata.hotHeight = document.getElementById("life-right-top").offsetHeight;
                //获取二级分类高度
                var seHeight = $api.domAll('#getHeight');
                for (var i = 0; i < seHeight.length; i++) {
                    vuedata.secondHeight.push(seHeight[i].clientHeight)
                }

                if (this.current == -1) {
                    //设置高度
                    window.pageYOffset = document.body.scrollTop = document.documentElement.scrollTop = 0;
                } else {
                    var jumpHeight = vuedata.hotHeight + 20;
                    for (var n = 0; n < this.current; n++) {
                        jumpHeight += vuedata.secondHeight[n];
                    }
                    //设置高度
                    window.pageYOffset = document.body.scrollTop = document.documentElement.scrollTop = jumpHeight;
                   // document.querySelector('#right').scroll(0,jumpHeight)


                }
            },
}

相关文章

网友评论

      本文标题:js 分类点击置顶

      本文链接:https://www.haomeiwen.com/subject/mnacyctx.html