我想在浏览器窗口的全屏模式下使用非常优秀的文本处理程序CodeMirror,并且我想为某种菜单添加一个固定的标题--或者至少为几个具有某些功能的按钮添加空间。
因此,我在顶部添加了一个div,并在div中添加了一个带有codemirror对象的填充顶。当有足够多的文本滚动发生时,problem就会出现。在将光标向下/滚动内容并再次向上移动之后,游标将位于div后面,但内容不会完全向下滚动。光标是隐藏的,我看不到内容。只有滚动通过滚动条工作。
我需要用固定的div修改html/css吗?或者,我是否需要检查光标是否在div后面/下面,并且必须让CodeMirror手动滚动?我试过了,但没有通过编程来实现:-(
<!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/
发布于 2015-06-20 20:10:45
我自己找到了解决办法。
我使用的不是两个重叠的div,而是两个div(不重叠的),样式为“位置:绝对”。它们不重叠,所以滚动很好。
<!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/
我希望我能得到一些评论,可能的副作用或缺点的立场绝对。不然的话,对我来说似乎没问题。
https://stackoverflow.com/questions/30932928
复制相似问题