UEditor百度富文本編輯器,解決圖片點擊錯位的問題


因項目中采用的是百度的富文本編輯器UEditor,然后圖片尺寸較大,點擊圖片想要修改尺寸,就出現了錯位的問題,這里記錄一下。

 

如下圖是錯位的截圖:

 

 

 可以明顯的看出這個提示的框出現了錯位的問題,然后怎么解決呢?

 

1.打開項目,找到UEditor官網下載的文件:ueditor.all.js

 

 

2.然后找到找到這個函數:attachTo: function (targetObj){}

 

 

代碼如下:

 1 attachTo: function (targetObj) {
 2                 var me = this,
 3                     target = me.target = targetObj,
 4                     resizer = this.resizer,
 5                     imgPos = domUtils.getXY(target),
 6                     iframePos = domUtils.getXY(me.editor.iframe),
 7                     editorPos = domUtils.getXY(resizer.parentNode);
 8 
 9                 domUtils.setStyles(resizer, {
10                     'width': target.width + 'px',
11                     'height': target.height + 'px',
12                     'left': iframePos.x + imgPos.x - me.editor.document.body.scrollLeft - editorPos.x - parseInt(resizer.style.borderLeftWidth) + 'px',
13                     //修改前
14                     //'top': iframePos.y + imgPos.y - me.editor.document.body.scrollTop - editorPos.y - parseInt(resizer.style.borderTopWidth) + 'px'
15                     //修改后
16                     'top': iframePos.y + imgPos.y - me.editor.document.documentElement.scrollTop - editorPos.y - parseInt(resizer.style.borderTopWidth) + 'px'
17                 });
18             }

 

 

3.注釋的是原來的方法,然后我們修改一下,再來看下效果:

 

 

 

 

 

轉載地址:改造:ueditor插入的圖片自適應編輯框大小,點擊圖片錯位問題

 

 


免責聲明!

本站轉載的文章為個人學習借鑒使用,本站對版權不負任何法律責任。如果侵犯了您的隱私權益,請聯系本站郵箱yoyou2525@163.com刪除。



 
粵ICP備18138465號   © 2018-2025 CODEPRJ.COM