【问题标题】:Resizing window with NicEditor使用 NicEditor 调整窗口大小
【发布时间】:2016-04-07 07:55:52
【问题描述】:

我正在使用 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');
  });

【问题讨论】:

  • 在每个窗口调整大小时重新加载 niceEdit!

标签: jquery html css autoresize


【解决方案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

【讨论】:

  • 检查你的小提琴!
  • @user3529020,很好。我已经纠正了你的解决方案。退房。还添加了参考网址。
【解决方案2】:

我找到了另一种简单的方法。在 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%';

就是这样。

【讨论】:

  • 我尝试了接受的答案,但没有奏效。但你的做到了。谢谢!
猜你喜欢
  • 2021-09-20
  • 1970-01-01
  • 1970-01-01
  • 2022-06-10
  • 1970-01-01
  • 2011-11-15
  • 2019-05-15
  • 2016-09-23
  • 1970-01-01
相关资源
最近更新 更多