【问题标题】:Why is scrolling to top not working html?为什么滚动到顶部不起作用 html?
【发布时间】:2022-05-27 09:20:41
【问题描述】:

我有一个 html,它是一个左右两侧的表格。左侧章节名称存在右侧所有章节内容存在。当我单击左侧的一章时,我希望在顶部看到该章。因此我写了这样的代码

_clickOnChapterTopic:function(obj){
                var aid  = obj.currentTarget.getAttribute('id');
                var id_rhp = aid+"_rhpend"; // this is id at end of each prev chapter 
                var classTag = '.'+id_rhp;
                this.$(classTag).scrollTop(0);
            }

滚动顶部 (0) 不起作用。当我打印它时,它总是 0 。

请建议

【问题讨论】:

    标签: html backbone.js


    【解决方案1】:

    你想更换

    this.$(classTag).scrollTop(0);
    

    this.$(classTag).scrollIntoView()
    

    或者,

    this.$(classTag).scrollTo(x-coord, y-coord)
    

    可能更适合您的需求。

    【讨论】:

    • html 页面有很多元素。就像我只希望这个类 div 到 top 。窗口滚动如何向右 div 移动到 0
    • 编辑了答案,现在试试
    • Ethan,你能指导另一个主干问题stackoverflow.com/questions/72404904/…
    猜你喜欢
    • 1970-01-01
    • 2014-01-06
    • 2013-05-26
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2017-07-20
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多