我正在使用以下内容:
<textarea
data-ui-tinymce="tinymceOptions"
data-ng-disabled="modal.action=='delete'"
data-ng-model="modal.formData.text"
id="inputText"
rows="20"
required></textarea>
当三角形出现时,高度只有几厘米。如何更改默认值首次出现时的高度?
以下是我正在使用的选项列表:
selector: "textarea",
plugins: [
"advlist autolink autosave link image lists charmap print preview hr anchor pagebreak spellchecker",
"searchreplace wordcount visualblocks visualchars code fullscreen insertdatetime media nonbreaking",
"table contextmenu template textcolor paste fullpage textcolor"
],
toolbar1: "bold italic underline strikethrough | alignleft aligncenter alignright alignjustify | styleselect fontselect fontsizeselect",
toolbar2: "cut copy paste | searchreplace | bullist numlist | outdent indent blockquote | undo redo | code | inserttime preview | forecolor backcolor",
toolbar3: "table | hr removeformat | subscript superscript | charmap | print fullscreen | spellchecker | visualchars visualblocks nonbreaking template pagebreak restoredraft",
menubar: false,
toolbar_items_size: 'small',
templates: [
{title: 'Test template 1', content: 'Test 1'},
{title: 'Test template 2', content: 'Test 2'}
]
来自javascript
tinymce.init({
selector: 'textarea',
height: 200
});
或来自html
<textarea style="height: 200px;">
您应该在CSS:中设置容器对象的高度
#inputText {
height : 10000000px;
}
4.X之前的tinyMCE版本,则此代码正在中工作
tinyMCE.init({
...,
setup: function(editor) {
editor.onInit.add(function() {
var width = editor.getWin().clientWidth;
var height = 50;
editor.theme.resizeTo(width, height);
});
}
});
对于tinyMCE版本4.X和之后的,则此代码正在中工作
tinyMCE.init({
setup: function (ed) {
ed.on('init', function(args) {
var id = ed.id;
var height = 25;
document.getElementById(id + '_ifr').style.height = height + 'px';
});
}
});
对于TinyMCE的全局高度设置,请编辑Django项目的settings.py:
TINYMCE_DEFAULT_CONFIG = {'height': 120}
对于每个小部件的设置,使用表单类中的mce_attrs
input = forms.CharField(widget=TinyMCE(mce_attrs={'height': 120}))
用django tinymce 2.7.0测试。
隐藏:您可以在为文本区域生成的HTML的data-mce-conf属性中看到类似"height": 120,
的字符串。否则,就会出问题。
对于版本6,以下代码应该可以使用
const wishedHeight = '100px'
// get `editor` from context of callbacks like `init`, `setup`, `loaded`, etc
editor.editorContainer.style.height = wishedHeight;
它对我有效(请参见setTimeout部分)
$(function () {
window.init_tinymce = function (id, custom_config) {
var textarea = $('#' + id);
// Default TinyMCE configuration
var basic_config = {
mode: 'none',
plugins: "link",
menu: 'none',
toolbar: 'bold | formatselect | link'
};
tinymce.init($.extend(basic_config, custom_config));
...
setTimeout(function(){ //wait for tinymce to load
console.log('timeout');
$(tinymce.editors[0].iframeElement).contents().find('body')
.css('min-height', $(tinymce.editors[0].contentAreaContainer).height() * .9);
}, 1000);
};
});
将此css添加到自定义样式表中,否则会降低所有现有编辑器的高度。
.mce-edit-area iframe {
max-height: 200px;
}