CKEditor 在插入元素之前获取图像宽度和高度(预加载)
有没有办法在实际将图像插入编辑器之前获取图像的宽度和高度?
我有以下代码,但宽度和高度总是返回 0
var imageElement = editor.document.createElement('img');
imageElement.setAttribute('src', imageSource);
var width = imageElement.$.width;
var height = imageElement.$.height;
if (width > 0) {
this.imageElement.setAttribute('width', width);
}
if (height > 0) {
this.imageElement.setAttribute('height', height);
}
editor.insertElement(imageElement);
帮助将不胜感激
Is there a way of getting the width and height of an image before actually inserting it into the editor?
I have the following code, but width and height always return 0
var imageElement = editor.document.createElement('img');
imageElement.setAttribute('src', imageSource);
var width = imageElement.$.width;
var height = imageElement.$.height;
if (width > 0) {
this.imageElement.setAttribute('width', width);
}
if (height > 0) {
this.imageElement.setAttribute('height', height);
}
editor.insertElement(imageElement);
Help would be greatly appreciated
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
我通过手动预加载图像解决了这个问题,但是我不知道这是否是 CKEditor 实现此
代码的方法:
I fixed this problem by preloading the image manually, however I do not know if this is the CKEditor way to achieve this
Code: