如何在鹅毛笔JS中添加图像
How to add image in Quill JS?
我不知道如何让图像像 http://quilljs.com/上的示例那样工作。
我尝试将<span title="Image" class="ql-format-button ql-image"></span>
添加到工具栏,从而添加按钮,但单击该按钮没有任何作用,我在文档中找不到任何内容。有什么建议吗?
更新的答案
从版本 1.0 及更高版本开始,您不再需要添加默认情况下包含的工具提示模块。 如何启用它的一个例子是这个。
<script>
var toolbarOptions = [
['bold', 'italic', 'underline', 'strike'], // toggled buttons
['blockquote', 'code-block'],
[{ 'header': 1 }, { 'header': 2 }], // custom button values
[{ 'list': 'ordered'}, { 'list': 'bullet' }],
[{ 'script': 'sub'}, { 'script': 'super' }], // superscript/subscript
[{ 'indent': '-1'}, { 'indent': '+1' }], // outdent/indent
[{ 'direction': 'rtl' }], // text direction
[{ 'size': ['small', false, 'large', 'huge'] }], // custom dropdown
[{ 'header': [1, 2, 3, 4, 5, 6, false] }],
[ 'link', 'image', 'video', 'formula' ], // add's image support
[{ 'color': [] }, { 'background': [] }], // dropdown with defaults from theme
[{ 'font': [] }],
[{ 'align': [] }],
['clean'] // remove formatting button
];
var quill = new Quill('#editor', {
modules: {
toolbar: toolbarOptions
},
theme: 'snow'
});
</script>
编辑:从 1.0 开始,这不再准确。克里斯·霍克斯的回答是正确的。
不幸的是,这似乎没有记录在任何地方,但您需要包含图像工具提示模块。例如,这是 quilljs.com 主页上的编辑器使用的:
quill = new Quill('#editor', {
modules: {
'toolbar': { container: '#toolbar' },
'image-tooltip': true,
'link-tooltip': true
},
theme: 'snow'
});
从 Quill 版本 1.3 开始,上述答案都不再有效。不幸的是,官方文档也没有太大进展。
您有两种方法可以解决问题,这两种方法都适用于官方主题雪与泡泡。无论哪种方式,您都不必添加以下代码:
'image-tooltip': true,
'link-tooltip': true
方式1:按如下方式初始化羽毛笔:
var editor = new Quill('#editorDiv',
{
modules: {
toolbar: [
...
['image'],
...
],
//not needed anymore: 'image-tooltip': true,
//not needed anymore: 'link-tooltip': true
...
},
...
});
方式2:按如下方式初始化羽毛笔:
<div id="editorToolbarDiv">
...
<button class="ql-image"></button>
</div>
<div id="editorDiv"></div>
var editor = new Quill('#editorDiv',
{
modules: {
toolbar: '#editorToolbarDiv',
//not needed anymore: 'image-tooltip': true,
//not needed anymore: 'link-tooltip': true,
...
},
...
});
从版本 1.3 开始,Quill 不支持调整图像大小。不过,可以使用自定义模块来做到这一点。
上面的答案在 js 中是正确的,但你必须将 html 添加到编辑器中,例如:
<span class="ql-format-group">
<span title="Link" class="ql-format-button ql-link"></span>
<span class="ql-format-separator"></span>
<span title="Image" class="ql-format-button ql-image"></span>
</span>
所以在那之后放入 js
quill = new Quill('#editor', {
modules: {
'toolbar': { container: '#toolbar' },
'image-tooltip': true,
'link-tooltip': true
},
theme: 'snow'
});
相关文章:
- jquery如何从计算机添加图像
- 如何从 URL 数组向文档添加图像列表
- 如何在fabric js中向多边形添加图像
- Bootstrap多选-在复选框后添加图像
- 通过纯JS添加图像
- 如何在鹅毛笔JS中添加图像
- 使用java脚本添加图像进行测验
- 如何添加可拖动的“;添加图像”;jquery中的图标
- 添加图像与点svg画布
- 是否可以添加图像作为徽标颜色框
- 如何使用fabric.js添加图像过滤器
- JavaScript-添加图像:React Native XCode
- Dropzone”;addedfile”;以程序方式添加图像时不会激发
- 在使用Jquery/Javascript单击下一个和上一个按钮时动态添加图像
- 用图像替换页面,而不是添加图像
- 如何获取动态添加图像的宽度和高度
- 如何在这个javascript中添加图像链接
- 尝试在画布中单击鼠标以添加图像
- 在剑道 UI 树视图项旁边添加图像不起作用
- 如何使用BEML或JS在全屏Brightcove智能播放器中添加图像叠加