是否可以在Quilljs编辑器中的textarea下面显示工具栏选项?

时间:2018-05-28 11:48:25

标签: javascript quill

如何在textarea下面显示工具栏。

我的代码:

var quill = new Quill('#txtMessage', {
  theme: 'snow',
  modules: {
    toolbar: {
      container: [
        ['bold', 'italic', 'underline'],
        [{
          'list': 'ordered'
        }, {
          'list': 'bullet'
        }],
        ['clean'],
        ['code-block'],
        [{
          'variables': ['{Name}', '{Email}']
        }],
      ],
      handlers: {
        "variables": function(value) {
          if (value) {
            const cursorPosition = this.quill.getSelection().index;
            this.quill.insertText(cursorPosition, value);
            this.quill.setSelection(cursorPosition + value.length);
          }
        }
      }
    }
  }
});

// Variables
const placeholderPickerItems = Array.prototype.slice.call(document.querySelectorAll('.ql-variables .ql-picker-item'));
placeholderPickerItems.forEach(item => item.textContent = item.dataset.value);
document.querySelector('.ql-variables .ql-picker-label').innerHTML = 'Variables' + document.querySelector('.ql-variables .ql-picker-label').innerHTML;
<script src="//cdn.quilljs.com/1.3.6/quill.js"></script>
<link href="//cdn.quilljs.com/1.3.6/quill.snow.css" rel="stylesheet"/>
<link href="//cdn.quilljs.com/1.3.6/quill.bubble.css" rel="stylesheet"/>

<div id="txtMessage"></div>

以上代码的输出: enter image description here

我想要输出如下: enter image description here 如何完成上述结果。

3 个答案:

答案 0 :(得分:1)

我不明白为什么不只使用css。

这样的事情:

&#13;
&#13;
var quill = new Quill('#editor-container', {
  modules: {
    toolbar: [
      [{
        header: [1, 2, false]
      }],
      ['bold', 'italic', 'underline'],
      ['image', 'code-block']
    ]
  },
  placeholder: 'Compose an epic...',
  theme: 'snow' // or 'bubble'
});
&#13;
#editor-container {
  height: 375px;
}

.editor-wrapper {
  position: relative;
}

.ql-toolbar {
  position: absolute;
  bottom: 0;
  width: 100%;
  transform: translateY(100%);
}
&#13;
<script src="//cdn.quilljs.com/1.3.6/quill.js"></script>
<link href="//cdn.quilljs.com/1.3.6/quill.snow.css" rel="stylesheet"/>
<link href="//cdn.quilljs.com/1.3.6/quill.bubble.css" rel="stylesheet"/>
<div class="editor-wrapper">
  <div id="editor-container">
  </div>
</div>
&#13;
&#13;
&#13;

https://codepen.io/moshfeu/pen/wXwqmg

答案 1 :(得分:0)

这可以解决问题:

.ql-container {
  display: flex;
  flex-direction: column-reverse; 
}

答案 2 :(得分:0)

您可以使用flexbox实现此目的。这样的事情应该可以解决问题:

<div class="d-flex flex-column-reverse">
   <div id="quill-editor"></div>
</div>

还请记住,您需要更新Quill css样式(边界等)

相关问题