首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >CodeMirror没有完全向下滚动,光标隐藏在div后面

问CodeMirror没有完全向下滚动,光标隐藏在div后面
EN

Stack Overflow用户
提问于 2015-06-19 07:57:18
回答 1查看 2.2K关注 0票数 3

我想在浏览器窗口的全屏模式下使用非常优秀的文本处理程序CodeMirror,并且我想为某种菜单添加一个固定的标题--或者至少为几个具有某些功能的按钮添加空间。

因此,我在顶部添加了一个div,并在div中添加了一个带有codemirror对象的填充顶。当有足够多的文本滚动发生时,problem就会出现。在将光标向下/滚动内容并再次向上移动之后,游标将位于div后面,但内容不会完全向下滚动。光标是隐藏的,我看不到内容。只有滚动通过滚动条工作。

我需要用固定的div修改html/css吗?或者,我是否需要检查光标是否在div后面/下面,并且必须让CodeMirror手动滚动?我试过了,但没有通过编程来实现:-(

代码语言:javascript
复制
<!DOCTYPE html>
<html>
<head>
    <meta charset="UTF-8">
    <link rel=stylesheet href="http://codemirror.net/doc/docs.css">
    <link rel=stylesheet href="http://codemirror.net/lib/codemirror.css">
    <script src=http://codemirror.net/lib/codemirror.js></script>
    <script src=http://codemirror.net/mode/htmlmixed/htmlmixed.js></script>
    <style type=text/css>
        .CodeMirror {float: left; width: 100%; height: 100%; }
    </style>  
</head>
<body>
  <div style="position: fixed; height: 28px; z-index:999; width: 100%; background: lightgray;">
    <button>Some action</button>
  </div>
  <div style="padding-top: 23px">
    <textarea id=content name="content"></textarea>
  </div>
    <script>
      var editor = CodeMirror.fromTextArea(document.getElementById('content'), {
        mode: 'application/x-httpd-php',
        lineNumbers: true
      });
    </script>
  </body>
</html>

在这里也可以查看:http://jsfiddle.net/fxvef3bw/1/

EN

回答 1

Stack Overflow用户

回答已采纳

发布于 2015-06-20 20:10:45

我自己找到了解决办法。

我使用的不是两个重叠的div,而是两个div(不重叠的),样式为“位置:绝对”。它们不重叠,所以滚动很好。

代码语言:javascript
复制
<!DOCTYPE html>
<html>
<head>
    <meta charset="UTF-8">
    <link rel=stylesheet href="http://codemirror.net/doc/docs.css">
    <link rel=stylesheet href="http://codemirror.net/lib/codemirror.css">
    <script src=http://codemirror.net/lib/codemirror.js></script>
    <script src=http://codemirror.net/mode/htmlmixed/htmlmixed.js></script>
    <style type=text/css>
        .CodeMirror {float: left; width: 100%; height: 100%; }
    </style>  
</head>
<body>
    <div style="padding: 1px; position: absolute; margin: 0px; top: 0px; bottom: auto; left: 0px; right: 0px; width: auto; height: 24px; background: lightgrey;">
        <button>some action</button>
    </div>
    <div style="padding: 1px; position: absolute; margin: 0px; left: 0px; right: 0px; top: 28px; bottom: 0px; width: auto; height: auto; ">
        <textarea id="content" name="content" style="display: none;"></textarea>
    </div>
    <script>
      var editor = CodeMirror.fromTextArea(document.getElementById('content'), {
        mode: 'application/x-httpd-php',
        lineNumbers: true
      });
    </script>
  </body>
</html>

更新的jsfiddle在这里:http://jsfiddle.net/fxvef3bw/2/

我希望我能得到一些评论,可能的副作用或缺点的立场绝对。不然的话,对我来说似乎没问题。

票数 2
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/30932928

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档