首页
学习
活动
专区
工具
TVP
发布
社区首页 >问答首页 >使文本适应于html文档中可拖动图像

使文本适应于html文档中可拖动图像
EN

Stack Overflow用户
提问于 2018-06-14 05:42:40
回答 1查看 30关注 0票数 0

我正在开发一个富文本编辑器,其中包括文本和图像。我试图找出一种方法,使文本在图像移动到文档的不同区域时环绕图像。我不完全确定从哪里开始。我的第一个直觉是将文档组织成div (表示段落)的集合,然后在指定的div中添加/删除图像。但问题是,我不能完全确定如何在触发javascript函数的gui中做到这一点。我最初的想法是计算文档中所有div的高度、宽度和位置,当图像的位置发生变化时,调用相关div的appendChild()/removeChild()方法(我可能必须动态生成元素‘d)。我想知道的是我在正确的轨道上吗?或者我应该以另一种方式批准这个问题?

仅供参考,我在一个移动设备上工作,解决方案必须是触摸屏。

EN

回答 1

Stack Overflow用户

发布于 2018-06-14 06:04:56

您可以通过使容器对象成为可内容编辑的div并使图像向左(或向右)浮动来实现这一点。

如果你想知道镜像的位置什么时候改变,你可以设置一个计时器来检查你检查的最后一个版本的innerHTML,或者,如果你只有一个镜像,你可以检查“

看看下面这段代码:

代码语言:javascript
复制
var lastText = document.querySelector(".container").innerText;
setInterval(function(){  
   var currText = document.querySelector(".container").innerText;
   if (lastText != currText) { alert("dom changed");}
    lastText = currText;
   }, 1000);
代码语言:javascript
复制
.img {
   float:left;
   height:200px;
   width:200px;
}
代码语言:javascript
复制
<div style="height:500px;width:500px;display:block;" contenteditable="true" class="container">

What is Lorem Ipsum?
<p>
<img src="https://static.igrice123.rs/slike/12378-3195/kuca-ze-ove-peki-:d.jpg" class="img" style="position:relative">
Lorem Ipsum is simply dummy text of the printing and typesetting industry. Lorem Ipsum has been the industry's standard dummy text ever since the 1500s, when an unknown printer took a galley of type and scrambled it to make a type specimen book. It has survived not only five centuries, but also the leap into electronic typesetting, remaining essentially unchanged. It was popularised in the 1960s with the release of Letraset sheets containing Lorem Ipsum passages, and more recently with desktop publishing software like Aldus PageMaker including versions of Lorem Ipsum.
<br><br>
Why do we use it?
<br><br>
It is a long established fact that a reader will be distracted by the readable content of a page when looking at its layout. The point of using Lorem Ipsum is that it has a more-or-less normal distribution of letters, as opposed to using 'Content here, content here', making it look like readable English. Many desktop publishing packages and web page editors now use Lorem Ipsum as their default model text, and a search for 'lorem ipsum' will uncover many web sites still in their infancy. Various versions have evolved over the years, sometimes by accident, sometimes on purpose (injected humour and the like).
<br><br>

Where does it come from?
<br><br>
Contrary to popular belief, Lorem Ipsum is not simply random text. It has roots in a piece of classical Latin literature from 45 BC, making it over 2000 years old. Richard McClintock, a Latin professor at Hampden-Sydney College in Virginia, looked up one of the more obscure Latin words, consectetur, from a Lorem Ipsum passage, and going through the cites of the word in classical literature, discovered the undoubtable source. Lorem Ipsum comes from sections 1.10.32 and 1.10.33 of "de Finibus Bonorum et Malorum" (The Extremes of Good and Evil) by Cicero, written in 45 BC. This book is a treatise on the theory of ethics, very popular during the Renaissance. The first line of Lorem Ipsum, "Lorem ipsum dolor sit amet..", comes from a line in section 1.10.32.
<br><br>
The standard chunk of Lorem Ipsum used since the 1500s is reproduced below for those interested. Sections 1.10.32 and 1.10.33 from "de Finibus Bonorum et Malorum" by Cicero are also reproduced in their exact original form, accompanied by English versions from the 1914 translation by H. Rackham.
</p>
</div>

票数 0
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/50846702

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档