我有一个关于CKEditor自动增长插件的问题:
按return键时(自动增长超过最小高度后),文本内容会抖动(向上一行并向下跳转),垂直滚动条会时断时续地闪烁。自动增长是可行的,但用户体验并不稳定。
我可以通过指定scrolling="no“和overflow="hidden”来隐藏垂直滚动条,但文本内容仍然会抖动。
我正在禁用ckeditor.js中的滚动功能:
<iframe scrolling="no" style="width:100%;height:100%;overflow:hidden;" frameBorder="0" title="'+E+'"'+' src="'+W+'"'+' tabIndex="'+(b.webkit?-1:C.tabIndex)+'"'+' allowTransparency="true"'+'></iframe>CKEditor初始化代码:
CKEDITOR.replace('Description',
{
sharedSpaces:
{
top: 'topSpace',
bottom: 'bottomSpace'
},
extraPlugins: 'autogrow,tableresize',
removePlugins: 'maximize,resize,elementspath',
skin: 'kama',
toolbar: [['Format', 'Font', 'FontSize'], ['Bold', 'Italic', 'Underline', 'Strike', 'Subscript', 'Superscript', '-', 'RemoveFormat'], ['TextColor', 'BGColor'], ['JustifyLeft', 'JustifyCenter', 'JustifyRight', 'JustifyBlock'], ['NumberedList', 'BulletedList'], ['Outdent', 'Indent'],
'/', ['Link', 'Unlink', 'Anchor'], ['Image', 'Flash', 'Table', 'HorizontalRule', 'SpecialChar'], ['PasteText', 'PasteFromWord'],['Cut','Copy','Paste'], ['Undo', 'Redo'], ['Find', 'Replace'], ['SpellChecker']],
toolbarCanCollapse: false,
pasteFromWordRemoveFontStyles: false,
enterMode: CKEDITOR.ENTER_BR,
shiftEnterMode: CKEDITOR.ENTER_P,
autoGrow_minHeight: 300
})有没有办法避免文本内容在按enter键时跳跃/移动(在超过最小高度后自动增长)?
发布于 2012-07-18 01:05:16
我今天一直在测试一个修复程序,我想我有一个适用于所有主流浏览器的有效解决方案。此外,我还修复了水平滚动条大小问题(水平滚动条不会增加编辑器的大小)。不过,这最终还是有点乱七八糟的(为了简单起见,滚动条高度被硬编码为17像素),所以我将提供两个版本,有没有水平滚动条的修复。
我知道正确的方法是创建一个补丁,并建议在下一版本的CKEditor中实现它,但这需要一段时间,所以在此期间,您可以这样做。您可以从下面的链接下载修改后的压缩plugin.js文件,并将其放置在CKEditor中的/plugins/autogrow/plugin.js路径中
不带水平滚动条的
到底做了什么改变?
我将通过未压缩(_source文件夹)文件来解释这些修改,这些文件是可读的,而压缩文件则很难阅读和理解。
我对自动增长临时标记做了一些小的修改,这个标记用于计算编辑器的新高度。这是_source (未压缩) autogrow/plugin.js第19行中新版本的标记代码。
var marker = CKEDITOR.dom.element.createFromHtml( '<span style="margin:0;padding:0;border:0;clear:both;width:1px;height:0px;font-size:0;display:block;"> </span>', doc );因此,高度从1像素更改为0像素,始终在标记元素内打印不间断的空格,并强制字体大小为零。在这些修改之后,这实际上解决了这个问题--而不是立即从DOM中删除标记,我将其改为通过1毫秒超时删除(未压缩的plugin.js文件中的第24行)。
setTimeout(function() {
marker.remove();
},1);水平滚动条修复
这有点乏味。我刚刚添加了一个检查编辑器scrollWidth是否比clientWidth大,如果是,那么在检查newHeight的最小值和最大允许值之前,向newHeight和currentHeight变量添加17个像素。
// TODO: calculate horizontal scrollbar height instead of using static 17 pixels
if ( scrollable.$.scrollWidth > scrollable.$.clientWidth ) {
newHeight += 17;
currentHeight += 17;
}
newHeight = Math.max( newHeight, min );
newHeight = Math.min( newHeight, max );可以使用How can I get the browser's scrollbar sizes? (或类似的)中描述的方法来计算滚动条大小,而不是使用17像素硬编码值,以使此修复更合适。
发布于 2013-12-17 20:05:42
body {overflow:隐藏;/Hide自动增长闪烁/}
(需要清除缓存到用户(resizeEditor)设置"Additional test)
newHeight += 20;//修复自动增长闪烁//(editor.config.autoGrow_bottomSpace || 0);
if (scrollable.$.scrollHeight > scrollable.clientHeight...
通过以下方式:
//Fix Autogrow flicker:
//contents.css change (test: clear css cache): body {overflow:hidden; /*Hide Autogrow flicker*/}
var editorBody = $(editor.editable().$);
if (newHeight >= max)
editorBody.css('overflow-y', 'visible');
else
editorBody.css('overflow-y', 'hidden');发布于 2011-12-15 16:40:48
AFAIK解决这个问题的唯一方法是修改CKEDitor的代码。(我建议在事件发生时处理“entry key”事件,而不是像它们那样超时)。
https://stackoverflow.com/questions/8484357
复制相似问题