简体   繁体   English

在CodeMirror中的给定行号上设置滚动条位置

[英]Set Scrollbar position at given line number in CodeMirror

I want to set the scrollbar position in codemirror at given line. 我想在给定行在codemirror中设置滚动条位置。 I am using scrollTo() method like below. 我正在使用如下的scrollTo()方法。 But it is not working. 但这是行不通的。 Let's say if there are total 100 lines, Initially I want to show user from line 61. 假设如果总共有100行,那么最初我想向61行显示用户。

editor = CodeMirror.fromTextArea(document.getElementById('cm'), {
              mode: "xml",
              theme: "default",
              lineNumbers: true
          });

editor.scrollTo(null,61);

Can anyone help me ? 谁能帮我 ?

Found solution : 找到的解决方案:

Use editor.setCursor(lineNumber) instead of scrollTo() method. 使用editor.setCursor(lineNumber)而不是scrollTo()方法。 It's working fine. 一切正常。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM