Jump to content

clearInterval Not Working


Recommended Posts

http://www.chameleonsoundscape.com/LiveSpace/index.html(Works in firefox, chrome, safari, and probably opera. If you use IE... don't use IE)I'm trying to make a desktop-like site with windows. I'm having a problem with my drag and resize function in certain cases. If you click on the title bar or resize icon you will start to drag or resize the window. It will usually work fine unless you right click (and the custom contextmenu I'm working on will come up) or if you select the title bar and try to drag the selection it will not stop the action of dragging or resizing. It will be best if you try it yourself and see what I mean. Just drag the window around, then try right-clicking in the middle of a drag and you will see whatever you do it will not stop dragging. If I try manually clearing the interval id ("Click STOP in the context menu") it still won't work.What can I do about this?Drag code-
dragParentInterval = null;resizeParentInterval = null;topZ = 10;$(document).mousemove(function(event){	mouseX = event.pageX;	mouseY = event.pageY;});function disableSelect(obj){	obj.onselectstart = function(){ return false; };	obj.onmousedown = function(){ return false; };}function enableSelect(obj){	obj.onselectstart = function(){  };	obj.onmousedown = function(){  };}function dragParent(){	dObj.css("left", mouseX - dOffsetX + "px");	dObj.css("top",  mouseY - dOffsetY + "px");}$(".window").live("mousedown", function(){	topZ++;	$(this).css("z-index", topZ);});$(".title_bar").live("mousedown", function(){		dObj = $(this).parent();	offset = dObj.offset();		dOffsetX = mouseX - offset.left;	dOffsetY = mouseY - offset.top;		$("#info").html("Window X: " + offset.left + "<br />Window y: " + offset.top);	$("#info").append("<br /><br />dOffsetX: " + dOffsetX + "<br />dOffsetY: " + dOffsetY);	$("#info").append("<br /><br />z-index: " + dObj.css("z-index"));	$("#info").append("<br /><br />left max: " + dObj.parent().width());	$("#info").append("<br /><br />top max: " + dObj.parent().height());		dragParentInterval = setInterval(dragParent, 50);	disableSelect(document);});$(window).mouseup(function(){	try	{		clearInterval(resizeParentInterval);	}	catch(e){}	try	{		clearInterval(dragParentInterval);	}	catch(e){}		enableSelect(document);});

Any ideas?

Edited by MrFish
Link to comment
Share on other sites

Not positive, but for your JQuery stuff, I would wait until the DOM loads first, by putting your code inside;

$(function() {   // Your code and functions...});

Also you might experiment with the newer release of JQuery, I've found v1.4.2 to be pretty stable.

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...