Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations SkipVought on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Dargging a div containing an IFRAME

Status
Not open for further replies.

y2k1981

Programmer
Aug 2, 2002
773
0
0
IE
I've been able to create a basic DIV which I can drag around the page. The code might not be the best, but it works so I'm happy enough for now ... well it almost works !!

It works fine if the DIV contains an image, text etc. The problem arises when I put an IFRAME in there. As soon as the mouse gets over the IFRAME during dragging, the DIV stops moving with it (because the onMouseMove is only being called when the mouse is over the parent. Can anybody help me figure out how to make it work properly? Do I need to do something with even bubbling (I don't even know exactly what that is exactly). my code is below. I just changed the color of the DIV temporarially so that I'd know when the onmousedown and onmouseup were being called:

Code:
<html>
<head>
<title>follow me ... </title>
<script type="text/javascript" language="JavaScript">

var moveIt = '';
var offsetX = 0;
var offSetY = 0;

function moveMe()
{
if(moveIt)
	{
		var obj = document.getElementById("image1");
		obj.style.left = event.clientX + offSetX + "px";// + window.document.documentElement.scrollLeft;
		obj.style.top = event.clientY + offSetY + "px";// + window.document.documentElement.scrollTop;
	}

}

function getOffSets()
{


offSetX = parseInt(document.getElementById("image1").style.left) - event.clientX; offSetY = parseInt(document.getElementById("image1").style.top) - event.clientY; //alert(offSetX + " " + offSetY);


}




</script>


</head>



<body onMouseMove = "moveMe(); return false">



<div onMouseUp="moveIt=''; image1.style.background='#f0f0f0'" onMouseDown="moveIt='true'; getOffSets(); image1.style.background='#000000';" id="image1" style="position: absolute; left: 0px; top: 0px; background: #f0f0f0" onMouseDown="return false;" onClick="moveMe()"><img src="iconfolder.gif"><br>
<iframe src="contacts/viewcontact.php?23" width="300" height="450"></div>


</body>

</html>
 
No, afraid not. if I hid the IFRAME, the user wouldn't see where the bottom of it was being placed. Besides, it wouldn't look very trendy would it !?!?

Surely there's a way around this? Perhaps it's got to do the times I'm calling the functions. Maybe I shouldn't call them with onMouseMove?
 
Please, can anybody help me out here at all??? I've been searching the net but not really found anything that can help me
 
if I hid the IFRAME, the user wouldn't see where the bottom of it was being placed.
You could put a border around it. I think the problem is that the browser can't redraw the IFRAME as fast as you can move the mouse. If you move the mouse slowly, it works. Not sure what else you can do.

Adam
 
yea, i see your point but I still think there has to be a better way. I've seen this done before. I think you're right also, the browser can't move the IFRAME as quick as the cursor, that's where the problem lies.

In the examples I've seen, the mouse still does move faster than the IFRAME, but it somehow manages to catch up with it
 
Cheers, thanks for that. I'll have a look. Just to let you know that I did try making the IFRAME invisilbe while it was being dragged and it worked.

anyway, I'm off to read that article now, thanks again
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top