简体   繁体   English

javascript / jquery / mootools / other js lib-如何使用户将div添加到现有网页

[英]javascript/jquery/mootools/other js lib- how to enable user to add a div to an existing web page

I am working with a web page, and showing it in a html editor. 我正在使用网页,并在html编辑器中显示它。

What I wan to do is, allow the user to dynamically define a new div within that html page, by dragging the mouse across the page- the page is being shown in a WYSIWYG Editor like CKEditor or TinyMCE...and the div is created, and code is inserted within the html of the page for that div. 我想做的是,允许用户通过在页面上拖动鼠标来动态定义该html页面中的新div-该页面正在CKEditor或TinyMCE之类的WYSIWYG编辑器中显示...并创建了div ,并将代码插入该div页面的html中。

I have no restriction with ref to using a specific javascript library- I am ok with use of jquery or mootools or any other library. 我对使用特定的javascript库没有任何限制-我可以使用jquery或mootools或任何其他库。

How do I even start thinking of implementing such a requirement? 我什至如何开始考虑实施这样的要求? How do I show a rectangle on the screen which is resizable, and when user is done dragging and he clicks the mouse, then a new div of the size of the rectangle is created? 如何在屏幕上显示可调整大小的矩形,当用户完成拖动并单击鼠标后,会创建一个矩形大小的新div? Can this be done using relative width/height? 可以使用相对宽度/高度完成此操作吗? Or will this necessarily require fixed width/height? 还是一定需要固定的宽度/高度?

Any pointers would be helpful for me... 任何指针都对我有帮助...

I'd probably use jQuery UI's resizeable. 我可能会使用jQuery UI的可调整大小。 When they click to add a div, append a new div on the page. 当他们单击以添加div时,请在页面上追加一个新的div。 $('<div></div>').resizable().appendTo(parent) . $('<div></div>').resizable().appendTo(parent) You should prob keep a reference of everything you've added to the page for saving it later. 您应该保留对添加到页面中的所有内容的引用,以供以后保存。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM