改造:ueditor插入的图片自适应编辑框大小,点击图片错位问题

在使用ueditor的编辑器时,需要让用户对插入的图片进行拉伸修改大小。当ueditor的编辑框内图片过大出现横竖向滚动条,且点击图片会错位,如图:

在这里插入图片描述

解决图片自适应屏幕大小

找到如下文件:\ueditor\themes\iframe.css
这个文件里,就能看到有这一句:/*可以在这里添加你自己的css*/
添加如下代码:

/*可以在这里添加你自己的css*/
img {
  max-width: 100%; /*图片自适应宽度*/
}
body {
  overflow-y: scroll !important;
}
.view {
  word-break: break-all;
}
.vote_area {
  display: block;
}
.vote_iframe {
  background-color: transparent;
  border: 0 none;
  height: 100%;
}

去掉点击图片拉伸效果添加此样式:#edui1_imagescale{display:none !important;} /*去除点击图片后出现的拉伸边框*/,根据网上搜索的方法,实际上没起作用,经过调试发现使用.edui-editor-imagescale {display: none !important;}可去除点击图片拉伸边框效果。

解决点击图片错位问题

点击较大尺寸图片回出现错位,导致图片下面内容无法编辑,如图:

在这里插入图片描述

修改ueditor.all.js代码
找见attachTo: function (targetObj) {}函数
在函数内如下修改:

domUtils.setStyles(resizer, {
    'width': target.width + 'px',
    'height': target.height + 'px',
    'left': iframePos.x + imgPos.x - me.editor.document.body.scrollLeft - editorPos.x - parseInt(resizer.style.borderLeftWidth) + 'px',
     //'top': iframePos.y + imgPos.y - me.editor.document.body.scrollTop - editorPos.y - parseInt(resizer.style.borderTopWidth) + 'px',
    'top': iframePos.y + imgPos.y - me.editor.document.documentElement.scrollTop - editorPos.y - parseInt(resizer.style.borderTopWidth) + 'px'
});

注释top行为源代码,下一行为修改后的代码

  • 2
    点赞
  • 8
    收藏
    觉得还不错? 一键收藏
  • 5
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论 5
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值