Jump to content

Can't get this to work in FireFox


aspnetguy

Recommended Posts

I can't get this drag and drop code to work in FireFox...it works fine in IE. Anyone see the trouble?

<html><head>	<title>OnMouseMove</title>	<script type="text/javascript">			//-------------------------------------------------------------		//Get Mouse Position Methods		//-------------------------------------------------------------		var _x;		var _y;		var _posx;		var _posy;		onload=		function()		{			_posx = document.getElementById('posx');			_posy = document.getElementById('posy');		}		function getPos(e)		{			if (!e)var e = window.event||window.Event;			if('undefined' != typeof e.pageX)			{				_x = e.pageX;				_y = e.pageY;			}			else			{				_x = e.clientX + document.body.scrollLeft;				_y = e.clientY + document.body.scrollTop;			}			_posx.value = _x;			_posy.value = _y;		}		function getX()		{			return _x;		}		function getY()		{			return _y;		}		if(window.Event && document.captureEvents)			document.captureEvents(Event.MOUSEMOVE);		document.onmousemove = function(){getPos();dragWindow();}				//-------------------------------------------------------------		//Create Window Methods		//-------------------------------------------------------------		var _w = 450;		var _h = 150;		var _border = '1px solid #818181';		var _c = 0;		var _pos = 'absolute';		var _t = 250;		var _l = 50;		var drag = false;		var winObj;		function createWindow()		{			var win = document.createElement('div');			win.style.width = _w + 'px';			win.style.height = _h + 'px';			win.style.border = _border;			win.style.position = _pos;			win.style.top = (_t + (_c*5)) + 'px';			win.style.left = (_l + (_c*5)) + 'px';			win.id = 'window' + _c;			_c++;			win.onmousedown = dragAndDrop;			document.onmouseup = dragAndDrop;						document.body.appendChild(win);		}		function dragAndDrop(e)		{			drag = !drag;			if(!e)var e = window.event;						if(drag)			{				if(document.all)					winObj = e.srcElement;				else					winObj = e.target;				var tmpWin = document.createElement('div');				tmpWin.id = 'tmpWin';				tmpWin.style.width = this.style.width;				tmpWin.style.height = this.style.height;				tmpWin.style.border = '1px dashed #dedede';				tmpWin.style.position = this.style.position;				tmpWin.style.top = this.style.top;				tmpWin.style.left = this.style.left;				document.body.appendChild(tmpWin);				}			else			{				var win = winObj;				var obj = document.getElementById('tmpWin');				win.style.top = obj.style.top;				win.style.left = obj.style.left;				document.body.removeChild(obj);			}		}		function dragWindow()		{			var obj = document.getElementById('tmpWin');			if(drag)			{				if(obj)				{					var x = getX();					var y = getY();					obj.style.top = y + 'px';					obj.style.left = x + 'px';					}			}		}		</script></head><body>	x <input type="text" size="5" id="posx"/> 	<br/>	y <input type="text" size="5" id="posy"/>	<br/><br/>		<a href="java script:createWindow()">Create Window</a></body></html>	

Link to comment
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
×
×
  • Create New...