Это всё решается. Допилю на днях, при наличии времени.
<!DOCTYPE html><html><head> <meta http-equiv="Content-Type" content="text/html; charset=windows-1251" /> <title>Перетаскивание и ресайз объектов в HTML средствами JS (Drag & Drop)</title> <style> * { margin: 0; padding: 0; } body { padding:20px; font:1em helvetica; color: #333; } .drag-window { position:absolute; -webkit-box-shadow: 4px 3px 5px rgba(0, 0, 0, 0.5); -moz-box-shadow: 4px 3px 5px rgba(0, 0, 0, 0.5); box-shadow: 4px 3px 5px rgba(0, 0, 0, 0.5); background: #dbdbdb; top: 60px; width: 400px; border: 3px double #333; z-index:10; overflow: hidden; min-width: 100px; min-height: 100px; max-height: 10000px; } .drag-window .title { position: relative; display: block; color: white; background: #666; padding: 10px 30px 10px 10px; cursor: move; } .drag-window.modal-active .title { background: #333; } .drag-window .title .close-button, .drag-window .title .min-button { position: absolute; right: 10px; top: 5px; color: #aaa; font-weight: bold; cursor: pointer; height: 6px; width: 6px } .drag-window .title .close-button:hover, .drag-window .title .min-button:hover { color: #777; } .drag-window .title .min-button { right: 20px; } .drag-window .content { padding:15px; } .resizeButton { position: absolute; right: 0; bottom: 0; margin-bottom: -4px; } .resizeButton img { cursor: se-resize; } </style> <script> if(document.getElementsByClassName) { getElementsByClass = function(classList, node) { return (node || document).getElementsByClassName(classList) } } else { getElementsByClass = function(classList, node) { var node = node || document, list = node.getElementsByTagName('*'), length = list.length, classArray = classList.split(/\s+/), classes = classArray.length, result = [], i,j for(i = 0; i < length; i++) { for(j = 0; j < classes; j++) { if(list[i].className.search('\\b' + classArray[j] + '\\b') != -1) { result.push(list[i]) break } } } return result } } function dragObject(evt, obj) { activeModal(obj); evt = evt || window.event; obj.clicked = true; obj.mousePosX = evt.clientX; obj.mousePosY = evt.clientY; if( evt.preventDefault ) evt.preventDefault(); else evt.returnValue = false; document.onmouseup = function(){ obj.clicked = false } document.onmousemove = function( evt ) { evt = evt || window.event; if( obj.clicked ) { posLeft = !obj.style.left ? obj.offsetLeft : parseInt( obj.style.left ); posTop = !obj.style.top ? obj.offsetTop : parseInt( obj.style.top ); mousePosX = evt.clientX; mousePosY = evt.clientY; var newX = posLeft + mousePosX - obj.mousePosX; var newY = posTop + mousePosY - obj.mousePosY; var newXright = newX + obj.offsetWidth; var newYbottom = newY + obj.offsetHeight; var scrollHeight = Math.max(document.documentElement.scrollHeight, document.documentElement.clientHeight); var scrollWidth = Math.max(document.documentElement.scrollWidth, document.documentElement.clientWidth); newX = newX < 0 ? 0 : newX; newY = newY < 0 ? 0 : newY; newX = newXright > scrollWidth ? scrollWidth - obj.offsetWidth : newX; newY = newYbottom > scrollHeight ? scrollHeight - obj.offsetHeight : newY; obj.style.left = newX + 'px'; obj.style.top = newY + 'px'; obj.mousePosX = mousePosX; obj.mousePosY = mousePosY; if(mousePosX < 0 || mousePosY < 0 || mousePosX > scrollWidth || mousePosY > scrollHeight) obj.clicked = false; } } } function resizeObject(evt, obj) { var scrollHeight = Math.max(document.documentElement.scrollHeight, document.documentElement.clientHeight); var scrollWidth = Math.max(document.documentElement.scrollWidth, document.documentElement.clientWidth); var borderH = 0; var borderW = 0; if (obj.currentStyle) { borderH += parseFloat(obj.currentStyle.borderTopWidth) + parseFloat(obj.currentStyle.borderBottomWidth); borderW += parseFloat(obj.currentStyle.borderLeftWidth) + parseFloat(obj.currentStyle.borderRightWidth); } else if (window.getComputedStyle) { borderH += parseFloat(document.defaultView.getComputedStyle(obj,null).borderTopWidth) + parseFloat(document.defaultView.getComputedStyle(obj,null).borderBottomWidth); borderW += parseFloat(document.defaultView.getComputedStyle(obj,null).borderLeftWidth) + parseFloat(document.defaultView.getComputedStyle(obj,null).borderRightWidth); } var posibleW = scrollWidth - obj.offsetLeft - borderW; var posibleH = scrollHeight - obj.offsetTop - borderH; evt = evt || window.event; obj.resize = true; obj.mousePosX = evt.clientX; obj.mousePosY = evt.clientY; if( evt.preventDefault ) evt.preventDefault(); else evt.returnValue = false; document.onmouseup = function(){ obj.resize = false } document.onmousemove = function( evt ) { evt = evt || window.event; if( obj.resize ) { objWidth = !obj.style.width ? obj.offsetWidth : parseInt( obj.style.width ); objHeight = !obj.style.height ? obj.offsetHeight : parseInt( obj.style.height ); mousePosX = evt.clientX; mousePosY = evt.clientY; var newW = objWidth + mousePosX - obj.mousePosX; var newH = objHeight + mousePosY - obj.mousePosY; newW = newW > posibleW ? posibleW : newW; newH = newH > posibleH ? posibleH : newH; obj.style.width = newW + 'px'; obj.style.height = newH + 'px'; obj.mousePosX = mousePosX; obj.mousePosY = mousePosY; if(mousePosX < 0 || mousePosY < 0 || mousePosX > scrollWidth || mousePosY > scrollHeight) obj.resize = false; } } } function createModal(content, title, noresizable, width, height) { //значения по умолчанию content = content || 'Содержимое окна'; title = title || 'Заголовок по умолчанию'; var elDiv = document.createElement('div'); elDiv.className = 'drag-window'; if (width) elDiv.style.width = width + 'px'; if (height) elDiv.style.height = height + 'px'; elDiv.onmousedown = function(){activeModal(this);}; document.body.appendChild(elDiv); activeModal(elDiv); elSpn = document.createElement('span'); elDiv.appendChild(elSpn); elSpn.className = 'title'; elSpn.innerHTML = title + ' <span title="свернуть/развернуть" class="min-button" onmousedown="minModal(this.parentNode.parentNode)">÷</span> <span title="закрыть" class="close-button" onmousedown="deleteModal(this.parentNode.parentNode)">×</span>'; elSpn.onmousedown = function(event){dragObject(event || window.event, this.parentNode);}; elContent = document.createElement('div'); elDiv.appendChild(elContent); elContent.className = 'content'; elContent.innerHTML = content; if(!noresizable) { elResize = document.createElement('div'); elDiv.appendChild(elResize); elResize.className = 'resizeButton'; elResize.innerHTML = '<img src="http://imgs.su/tmp/2012-10-07/1349554018-492.jpg" alt="" onmousedown="resizeObject(event, this.parentNode.parentNode)" />'; } } function deleteModal(elem) { elem.parentNode.removeChild(elem); } function minModal(elem) { var divResize = getElementsByClass('resizeButton', elem)[0]; var divTitle = getElementsByClass('title', elem)[0]; if (elem.style.minHeight == '0px') { elem.style.maxHeight = '10000px'; elem.style.minHeight = '100px'; if(divResize) divResize.style.display = 'block'; } else { elem.style.maxHeight = divTitle.offsetHeight + 'px'; elem.style.minHeight = '0'; if(divResize) divResize.style.display = 'none'; } } function classManipulation(e,v,n,c,r){r=e[c='className'].replace(eval('/\\b'+n+'\\b/g'),'');return'has'==v?r!=e[c]:e[c]={add:1,toggle:r==e[c]}[v]?r+' '+n:r} function activeModal(elem) { objs = getElementsByClass('modal-active'); for (i = 0; i < objs.length; i++) { objs[i].style.zIndex = 10; classManipulation(objs[i], 'remove', 'modal-active'); } classManipulation(elem, 'add', 'modal-active'); elem.style.zIndex = 11; } </script> </head> <body> <code> var con = 'Lorem ipsum dolor sit amet, consectetuer adipiscing elit, sed diam nonummy nibh euismod tincidunt ut laoreet dolore magna <a href="#">aliquam erat</a> volutpat.';<br /> var tit = 'Заголовок';<br /> var noresizbl = false; //false - можно ресайзить, true - нельзя<br /> var wid = 400;<br /> var heig = 300;<br /> </code> <div id="result"></div> <script> var con = 'Lorem ipsum dolor sit amet, consectetuer adipiscing elit, sed diam nonummy nibh euismod tincidunt ut laoreet dolore magna <a href="#">aliquam erat</a> volutpat.'; var tit = 'Заголовок'; var noresizbl = false; //false - можно ресайзить, true - нельзя var wid = 400; var heig = 300; createModal(con, 'Окно при загрузке документа с длинным заголовком для проверки') </script> <p><a href="#" onclick="createModal(con, tit, noresizbl, wid, heig)" >Еще окно <strong>createModal(con, tit, noresizbl, wid, heig)</strong></a></p> <p><a href="#" onclick="createModal(con, tit, true, wid, heig)" >Нересайзебльное окно <strong>createModal(con, tit, true, wid, heig)</strong></a></p> <p><a href="#" onclick="createModal(con, tit)" >Окно с неуказанными ширина/высота <strong>createModal(con, tit)</strong></a></p> <p><a href="#" onclick="createModal(con)" >Окно без заголовка <strong>createModal(con)</strong></a></p> <p><a href="#" onclick="createModal(con, tit)" >Еще окно <strong>createModal(con, tit)</strong></a></p> </body> </html>
<div style="display:none;" class="div_rd"><span class="winminmax" ></span><div class="title"></div><div class="content"></div></div>