【问题标题】:How to make automatic scrolling to the desired word in the text如何自动滚动到文本中所需的单词
【发布时间】:2018-10-11 15:47:08
【问题描述】:

当我从搜索移动到文本区域中存在大文本的所需单词时,我已经有了这个单词的第一个索引和最后一个索引。有了这个,我会 setSelectionRange (firstIndex, lastIndex)focus ()

但问题是自动滚动到这个词不起作用,你需要手动滚动才能看到突出显示的词。如何解决这个问题?

  ngOnInit() {
    const subscription = this.pageService.subject.subscribe(
      r => {
        setTimeout(() => {
          this.textareaNovel.nativeElement.focus();
          const firstIndex = this.pageService.allIndex[this.pageService.indexOfOne];
          const lastIndex = firstIndex + this.pageService.inputSearchText.length;
          this.textareaNovel.nativeElement.setSelectionRange(firstIndex,lastIndex);
        }, 100);
      },
      e => console.error(e),
      () => console.info("completed")
    );
  }

【问题讨论】:

    标签: javascript angular textarea


    【解决方案1】:

    var objDiv = document.getElementById("divExample"); objDiv.scrollTop = 50

    你可以用它来滚动任何你想要的地方,如果你能找到你可以插入的文本位置。希望这会有所帮助:)

    【讨论】:

    • 谢谢,但问题是在textarea里面没有
      。我只知道单词的索引
    猜你喜欢
    • 2021-03-12
    • 2019-11-30
    • 1970-01-01
    • 2015-08-20
    • 1970-01-01
    • 2013-07-16
    • 1970-01-01
    • 2010-10-28
    • 1970-01-01
    相关资源
    最近更新 更多