使用NicEditor调整窗口大小

时间:2016-01-03 16:18:41

标签: jquery html css autoresize

我正在使用NicEditor(http://nicedit.com)。

首先,我将textarea的宽度设置为100%,但是当我调整窗口大小时,编辑器保持不变,并且不会调整窗口的新100%宽度。

<textarea style="width: 100%;"> something .. </textarea>

<script>
    //<![CDATA[
bkLib.onDomLoaded(function() { nicEditors.allTextAreas() });
//]]>

</script> 

我该如何解决这个问题?

修改 我找到了一个有效的解决方案:

  $(function () {
      editor = new nicEditor({fullPanel : false}).panelInstance('text');
  })

  $(window).resize(function() {
     editor.removeInstance('text'); 
     editor = new nicEditor({fullPanel : false}).panelInstance('text');
  });

2 个答案:

答案 0 :(得分:1)

默认情况下,Nice Editor或CK Editor没有响应功能。

尝试以下内容。通过父元素控制宽度和高度。

    <textarea id="comments" style="width:100%; height:100%;"></textarea>

在每个窗口调整大小时,调用NiceEdit

JS:

  var editor;
  function reLoadEditor() {
      editor.removeInstance('comments'); 
      editor = new nicEditor({fullPanel : false}).panelInstance('comments');
  }();

  $(window).resize( function() {
     reLoadEditor();
  } );

参考 - 演示3:添加/删除NicEditors:
http://nicedit.com/demos.php?demo=3

答案 1 :(得分:0)

我找到了另一种简单的方法。在nicEdit.js文件更改中,您只需更改2行:

第453行附近更改了“宽度”。

原文:

var panelElm = new bkElement('DIV').setStyle({
  width: (parseInt(e.getStyle('width')) || e.clientWidth) + 'px'
}).appendBefore(e);

新功能:

var panelElm = new bkElement('DIV').setStyle({
  width: '100%'
}).appendBefore(e);

在554行附近,您还必须更改“宽度”。

原始:

newX = parseInt(e.getStyle('width')) || e.clientWidth;

新功能:

newX = '100%';

仅此而已。

相关问题