I'm not thrilled with the code but, its not horrible. Here it is (from Sample 06 at the link you mentioned) modified to limit you to the area of the window at the left and bottom edges, thus preventing scrollbars if none were present to begin with:
Code:
<script type='text/javascript'>
var ie = document.all;
var nn6 = document.getElementById &&! document.all;
function iecompattest(){
return (document.compatMode && document.compatMode!="BackCompat")? document.documentElement : document.body;
}
var isdrag = false;
var x, y;
var dobj;
function movemouse( e ) {
if( isdrag ) {
var scrollt=typeof pageYOffset=='number'? pageYOffset : iecompattest().scrollTop? iecompattest().scrollTop : 0;
var scrolll=typeof pageXOffset=='number'? pageXOffset : iecompattest().scrollLeft? iecompattest().scrollLeft : 0;
var leftlim=window.innerWidth? window.innerWidth-dobj.offsetWidth : iecompattest().clientWidth-dobj.offsetWidth;
var leftset=nn6 ? tx + e.clientX - x : tx + event.clientX - x;
var toplim=window.innerHeight? window.innerHeight-dobj.offsetHeight : iecompattest().clientHeight-dobj.offsetHeight;
var topset=nn6 ? ty + e.clientY - y : ty + event.clientY - y;
dobj.style.left = Math.min(leftset, leftlim+scrolll)+'px';
dobj.style.top = Math.min(topset, toplim+scrollt)+'px';
return false;
}
}
function selectmouse( e ) {
var fobj = nn6 ? e.target : event.srcElement;
var topelement = nn6 ? "HTML" : "BODY";
while (fobj.tagName != topelement && fobj.className != "dragme") {
fobj = nn6 ? fobj.parentNode : fobj.parentElement;
}
if (fobj.className=="dragme") {
isdrag = true;
dobj = document.getElementById("styled_popup");
tx = parseInt(dobj.style.left+0);
ty = parseInt(dobj.style.top+0);
x = nn6 ? e.clientX : event.clientX;
y = nn6 ? e.clientY : event.clientY;
document.onmousemove=movemouse;
return false;
}
}
function styledPopupClose() {
document.getElementById("styled_popup").style.display = "none";
}
document.onmousedown=selectmouse;
document.onmouseup=new Function("isdrag=false");
</script>
Notes: It will also work with a DOCTYPE, something the original did not do. If the page already has scrollbars, you are limited to the viewable area but, may scroll the page (left or down) and then drag into the newly revealed areas.
Bookmarks