删除 contentEditable div 上的调整大小处理程序
我创建了一个 contentEditable div 用作富文本区域。它周围有我想摆脱的调整大小处理程序。知道我该怎么做吗?
编辑:这似乎正在发生,因为我绝对定位了 div,因此 Firefox 向元素添加了一个令人恼火的 _moz_resize 属性,我无法关闭该属性。
I created a contentEditable div to use as a rich textarea. It has resize handlers around it that I'd like to get rid of. Any idea how I'd do this?
Edit: This appears to be happening because I am absolutely positioning the div, so Firefox adds an infuriating _moz_resize attribute to the element which I cannot turn off.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(7)
顺便说一句,您可以通过向文档发送(记录有些少的)
enableObjectResizing
命令来禁用 Firefox 的自动调整大小处理功能:AFAIK,只有在文档加载后才能安全地执行此操作,据我所知,没有办法禁用抓取器,这是一个单独的功能。
Just as a side note, you can disable Firefox's automatic resize handle feature by sending the (somewhat poorly-documented)
enableObjectResizing
command to the document:AFAIK, this can only safely be done once the document has loaded, and there's no way I know of to disable the grabber, which is a separate feature.
看来我可以通过添加包装器 div 并绝对定位包装器然后使内部 div 内容可编辑来解决此问题。
It looks like I'll be able to work around this by adding a wrapper div and absolutely positioning the wrapper and then making the inner div contentEditable.
在 Chrome 39 中,这些句柄似乎不存在,即使您希望它们存在。
在 Firefox 中,可以简单地使用 execCommand,就像 ZoogieZork 回答的那样。
但在 Internet Explorer 中,此功能无法关闭。必须解决这个问题。
在 WYMeditor 开发中,这是我发现的。
结果如下:
mouseup
选择的文本鼠标移动
将导致选择图像。这是我经过几个小时的深呼吸后能想到的最好的办法。我认为如果你真的想摆脱这些手柄就足够了。
在 IE 中,设置
oncontrolselect
在图像上返回false
确实可以防止这些句柄出现,并且您可以通过将以下处理程序附加到来巧妙地做到这一点>mousedown
事件:它实际上不能完全正常工作。它工作得不太好的原因是,为了开始对图像进行拖放操作,必须按住鼠标而不移动它一瞬间,然后才开始移动它一段时间。阻力。如果按下鼠标并立即开始拖动,图像将保留在其位置并且不会被拖动。
所以我没有那么做。
我所做的如下。在所有浏览器中,我都使用
mouseup
来专门通过文本选择目标图像。在非 IE 和 IE11 中,同步:在 IE 7 到 10 中,异步:
这确保了这些句柄出现后,它们会尽快消失,因为图像会丢失其“控件选择”,因为该选择被替换为常规文本选择。
在 Internet Explorer 7 到 11 中,我将一个处理程序附加到
dragend
来删除所有选择:这使得拖放后显示的手柄消失。
我希望这对您有所帮助,并且希望您能做得更好。
In Chrome 39, these handles don't seem to exist, even if you wanted them to.
In Firefox, one can simply use
execCommand
, like ZoogieZork answered.But in Internet Explorer this can't be turned off. It must be worked around.
In WYMeditor development, here's what I've found.
The following results in:
mouseup
mouseup
will result in an image being selected.This is the best I could come up with after hours of very deep breaths. I think it is good enough if you really want to get rid of those handles.
In IE, Setting
oncontrolselect
to returnfalse
on the image, really does prevent those handles from appearing, and you can do it cleverly, by attaching the following handler to themousedown
event:It actually doesn't work completely well. The reason that it didn't work very well is that in order to begin a drag and drop operation on the image, one had to press and hold the mouse, without moving it, for a split second, and only then begin moving it for the drag. If one pressed the mouse and immediately began dragging, the image would remain in its place and not be dragged.
So I didn't do that.
What I did is the following. In all browsers, I used
mouseup
to text select the target image exclusively. In non-IE and IE11, synchronously:In IE 7 through 10, asynchronously:
This made sure that after those handles show up, they disappear ASAP, because the image loses its "control selection" because that selection is replaced with a regular text selection.
In Internet Explorer 7 through 11, I attached a handler to
dragend
that removes all selection:This makes the handles that show up after drag and drop, disappear.
I hope this helps and I hope you can make it even better.
我只是面临这个问题。
我尝试了
document.execCommand("enableObjectResizing", false, false);
但是,移动图标仍然出现。当onmousedown
事件发生时,解决我的问题的只是e.preventDefault()
。I just face that problem.
I tried
document.execCommand("enableObjectResizing", false, false);
but, the move icon was still appearing. What just fix my problem was juste.preventDefault()
whenonmousedown
event occurs.对于 IE11(我没有测试过旧版本的 IE,但我觉得它会起作用),您可以将 contenteditable="false" 属性添加到 img 标签。这将防止在保持拖放到位的同时进行任何大小调整。
for IE11 (I havn't tested the older versions of IE, but I feel like it would work) you can add contenteditable="false" attribute to the img tag. This will prevent any re-sizing from being done while keeping drag and drop in place.
...只是有史以来最好的修复
或包装您的 input/img 的任何 html 元素
像魅力一样在 IE11 上工作
... just the best fix ever
or any html element that wraps your input/img
Works on IE11 like a charm
您是否尝试过将样式添加
到 div 中?
Have you tried adding the style
to the div?