2017-01-23 184 views
0

我使用froala 2.4.0内联编辑器来实现Facebook的后类似功能。我已经emebeded froala编辑器在一个div中,如下图所示。现在我想让父div可扩展,即随着froala编辑器内容的变化而增长/缩小。边框是父div,占位符行是Froala内联编辑器。有没有办法做到这一点? enter image description here使得Froala编辑器的父div的高度可扩展

这是我走到这一步:

$(function() { 
 
    $('#custom-post-feed-text').froalaEditor({ 
 
    toolbarInline: true, 
 
    charCounterCount: false, 
 
    placeholderText: 'Share what\'s on your mind...', 
 
    toolbarButtons: [], 
 
    quickInsertButtons: [] 
 
    }) 
 
});
<link href="https://cdnjs.cloudflare.com/ajax/libs/froala-editor/2.4.0/css/froala_editor.pkgd.css" rel="stylesheet"/> 
 
<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script> 
 
<script src="https://cdnjs.cloudflare.com/ajax/libs/froala-editor/2.4.0/js/froala_editor.pkgd.min.js"></script> 
 

 
<div class="custom-post-feed-container" id="custom-post-feed-container-personal"> 
 
    <div class="custom-post-feed-textarea"> 
 
    <textarea id="custom-post-feed-text"></textarea> 
 
    </div> 
 
    <div class="custom-post-feed-options"> 
 
    <span class="custom-post-feed-more-options" id="custom-feed-more-options" title="More">+</span> 
 
    <span id="more-option"> 
 
     <span title="Upload image"><i class="fa fa-camera" aria-hidden="true"></i></span> 
 
     <span title="Embed link"><i class="fa fa-link" aria-hidden="true"></i></span> 
 
     <span title="Upload video"><i class="fa fa-video-camera" aria-hidden="true"></i></span> 
 
     <span title="Add Poll"><i class="fa fa-pie-chart" aria-hidden="true"></i></span> 
 
    </span> 
 
    </div> 
 
</div>

+0

此外,我想知道是否有任何的焦点事件我可以使用。一旦用户关注编辑器,我需要执行一些代码。在这种情况下,jquery的普通.focus()函数不起作用。 –

+0

你有没有试过autosize.js? – Gacci

+0

除非你在某处设置了高度,否则div应该展开。我们可以看到更多的代码或完整的实例吗? –

回答

1

Froala编辑器支持自动增长功能,您可以设置一个heightMin和M and heightMax`并会自动在高度增长的用户类型。请参阅该文档

https://www.froala.com/wysiwyg-editor/examples/adjustable-height

$(function() { 
    $('#custom-post-feed-text').froalaEditor({ 
    toolbarInline: true, 
    charCounterCount: false, 
    placeholderText: 'Share what\'s on your mind...', 
    toolbarButtons: [], 
    quickInsertButtons: [] 
    heightMin: 50, 
    heightMax: 200 
    }) 
}); 

对于你的目的如果父DIV没有为custom-post-feed-textarea任何固定的高度会自动增长

+0

Thanx的帮助! –