如何改变的CKEditor的编辑大小?

问题描述 投票:27回答:20

既然是一个textarea,我试着在HTML属性的cols =“50”,但它不工作。

另外,我发现从以前的问题的答案。他说,我可以通过添加做到这一点。 CKEDITOR.instances.myinstance.resize(1000, 900);然而,尺寸仍没有改变。

下面是我尝试的代码,谢谢。

更新

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html>
<head>
    <script src="../plugin/jquery-1.6.1.min.js"></script>
    <script src="../plugin/jquery.validate.min.js"></script>
    <script type="text/javascript" src="../plugin/ckeditor/ckeditor.js"></script>

    <script>
$(document).ready(function(){   
$("#addlist").validate();
var editor = CKEDITOR.replace('editor1');
var div = document.getElementById('editor');
editor.resize($(div).width(),'900');
}); 
    </script>
</head>
<body>
    <form method="post" action="confirm.php">
        <p><br />
        <div id="editor">
            <textarea id="editor1" name="editor1">
            </div>
            <? if (isset($_GET['file']))
            {$filepath=$_GET['file']; 
                require_once("../template/".$filepath);}?> </textarea>
        </p>
        </br>
            File Name </br>
            <b>(Naming Without .html e.g. MyTemplate1) :</b>
            </br>
            <input id="tname" name="tname" class="required" />

            <input type="submit" />

        </p>
    </form>
</body>
</html>
javascript jquery html ckeditor
20个回答
19
投票

尝试以下

为了实现这一点,使用resize函数来定义编辑器界面的尺寸,分配窗口以像素或CSS-接受单元的宽度和高度值。

// Set editor width to 100% and height to 350px.
editor.resize( '100%', '350' )

在设置高度值,使用isContentHeight参数来决定的值是否适用于整个编辑界面,或只是编辑区域。

// The height value now applies to the editing area.
editor.resize( '100%', '350', true )

http://docs.cksource.com/CKEditor_3.x/Howto/Editor_Size_On_The_Fly


2
投票

使用config更新样式

editor.config.width="100%";
editor.config.height="100px"

2
投票

CKEDITOR调整大小:

CKEDITOR.replace('OnThisDateIwillLook',
{
    toolbar: [['Bold', 'Italic', 'Underline'],],
    skin: 'v2',               
    extraPlugins: 'autogrow',
    autoGrow_minHeight: 250,
    //autoGrow_maxHeight: auto,
});

1
投票

在其他的答案中所述的调整大小()函数是必须使用的。对于那些谁不知道如何代码可用于editor.resize( '100%', '350' )见下文。

假设你创建与name属性测试一个文本编辑器。然后,你可以调用这样的CKEditor的实例的大小调整()函数:

CKEDITOR.instances.test.resize( '100%', '80');

1
投票
CKEDITOR.config.width="80%";
CKEDITOR.config.height="500px"

1
投票

回答这个问题,因为我花了永远找出如何解决这个使用jQuery。这类似于上述一些答案,但包含的实例创建要彻底。

在我看来,这是不优雅,我不知道为什么CKEDITOR没有内在它的大小,从它的父容器,这将是理想得多。

 var new_editor = $('#selected_textarea').ckeditor(function(){ 
      var set_editor_height = $('#parent_container').height()
      $('.cke_contents').css({ 'height': set_editor_height });
     });

这应该适用于类选择,而不仅仅是ID。


1
投票

要在初始化时设定的CKEditor的高度,你可以按照上市程序。

<script>
       CKEDITOR.replace( 'editor1',{
          height:['500px']
       });
</script>

0
投票

使用jQuery ckeditor,它最终会听我的话,用一个黑客位的唯一途径:

    $('.ckeditor textarea').ckeditor(function () {
        editor = $('.ckeditor textarea').ckeditorGet();
        $('.cke_inner').css({ 'width': '802px' });
    });

0
投票
editor.resize('100%', '350');
editor.resize('550', '350');

0
投票

这个人是完美。

<script type="text/javascript">
    CKEDITOR.replace('article-ckeditor',
    {
    height: '800px',
    });
</script>

0
投票

如果你需要100%的高度对编辑器;

setInterval(function(){ 
      $('#cke_1_contents').css('height', $('#parent_div_id').outerHeight());
}, 700);

14
投票

对于CKEditor的4.0,我不得不使用:

  CKEDITOR.replace('body', {height: 500});

0
投票

首先,定义文本区域。

<textarea type="text" name="title" id="textEditor" required></textarea>

然后在script标签初始化CK编辑器。

<script type="text/javascript">
    CKEDITOR.replace('textEditor',
    {
       height: '800px'
    });
</script>

14
投票

只要到CKEDITOR文件夹,找到config.js

    CKEDITOR.editorConfig = function( config ) {
    // Define changes to default configuration here. For example:
    // config.language = 'fr';
    // config.uiColor = '#AADC6E';
     config.height = '80vh';

};

这将根据屏幕大小调整您的CKEditor。


8
投票

//这将help.It只是为我工作。

<script>
            CKEDITOR.replace( 'editor1', {
                uiColor: '#14B8C4',
                toolbar: [
                    [ 'Bold', 'Italic', '-', 'NumberedList', 'BulletedList', '-', 'Link', 'Unlink' ],
                    [ 'FontSize', 'TextColor', 'BGColor' ]
                ],
                width:['250px']

            });

</script>

4
投票

下面是一个使用的cols一个jQuery功能=属性来调整CKEditor的高度(每行20像素的标量)

(function($) {
jQuery.fn.cke_resize = function() {
   return this.each(function() {
      var $this = $(this);
      var rows = $this.attr('rows');
      var height = rows * 20;
      $this.next("div.cke").find(".cke_contents").css("height", height);
   });
};
})(jQuery);

CKEDITOR.on( 'instanceReady', function(){
  $("textarea.ckeditor").cke_resize();
})

那么你的HTML这样会自动调整

<textarea name="body" class="ckeditor" rows="10"></textarea>

4
投票

我用这个溶液(CKeditor4):

.cke_contents { height: 100% !important; }

source

希望能帮助到你 :)


3
投票
Yes this worked perfectly We have to use config to override the styles



    <textarea  rows="1000" id="editor1" name="newsletter"></textarea>
    <script>
    CKEDITOR.replace('editor1');
    CKEDITOR.config.width="100%";
    CKEDITOR.config.height="700px"
    </script>

3
投票

在CKEditor的版本4.5.5

可以通过使用武力改变高度


CKEDITOR.config.height = '800像素';



2
投票

我挣扎着,在4.3.4版本使用大小调整方法。

我做了黑客及以下CSS使用: -

.cke_reset {width:807px !important; }

工作就像一个魅力!

© www.soinside.com 2019 - 2024. All rights reserved.