Hello and welcome to our community! Is this your first visit?
Register
Enjoy an ad free experience by logging in. Not a member yet? Register.
Results 1 to 5 of 5
  1. #1
    New to the CF scene
    Join Date
    Jun 2009
    Posts
    3
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Where do I put setInverval?

    I have an overloaded div on my page that is scrolled by the position of the mouse in the window. It uses the onmousemove event to tell the position of the mouse. I want to use setInterval, or sonething, so that it will continually update the position of the mouse. It currently only registers the position when the mouse is moving, so it stops scrolling when the mouse stops moving.
    The page is at http://www.nicnok.net/HTML/gallery/gallery.html
    I'll assume you know how to get the html and so I won't take up space with it here. Thanks in advance for your help. The .js code is

    Code:
    document.onmousemove = CurPos;
    
    function CurPos(evt) {
    	if (!evt) {
    		evt = window.event;
    	}
    		moveGal(evt.clientX);
    }
    
    function moveGal(xPos) {
    	
    	var stageWidth = document.width;
    	var speed = 15;
    	var galWidth = document.getElementById("whole").offsetWidth;
    	var galX = document.getElementById("whole").offsetLeft;
    	var galView = document.getElementById("container").offsetWidth;
    	
    	var xDist = xPos-(stageWidth/2);
    	
    	galX = galX+((0-xDist)/speed);
    	
    	if (galX>=0) {
    			galX = 0;
    	}
    	if (galX<=galView-galWidth) {
    			galX = galView-galWidth;
    	}
    
    	document.getElementById("whole").style.left=galX+"px";
    }

  • #2
    Regular Coder ninnypants's Avatar
    Join Date
    Apr 2008
    Location
    Utah
    Posts
    504
    Thanks
    10
    Thanked 47 Times in 47 Posts
    you should be able to just replace this:
    Code:
    document.onmousemove = CurPos;
    With:
    Code:
    setInterval("CurPos()", 5000);//5000 = 5 seconds
    I'm not sure how this will work with event's though, but you should be able to get the mouses x position without an event

  • #3
    New to the CF scene
    Join Date
    Jun 2009
    Posts
    3
    Thanks
    0
    Thanked 0 Times in 0 Posts
    I tried just swapping in your code, but nothing. This is what I was trying to do before I just settled for the mouse event; but it wouldn't work either.

    Code:
    setInterval("moveGal()", 500);
    
    function moveGal() {
    	
    	if (!evt) {
    		evt = window.event;
    	}
    	
    	var xPos=evt.clientX;
    	
    	var stageWidth = document.width;
    	var speed = 15;
    	var galWidth = document.getElementById("whole").offsetWidth;
    	var galX = document.getElementById("whole").offsetLeft;
    	var galView = document.getElementById("container").offsetWidth;
    	
    	var xDist = xPos-(stageWidth/2);
    	
    	galX = galX+((0-xDist)/speed);
    	
    	if (galX>=0) {
    			galX = 0;
    	}
    	if (galX<=galView-galWidth) {
    			galX = galView-galWidth;
    	}
    
    	document.getElementById("whole").style.left=galX+"px";
    }

  • #4
    Banned
    Join Date
    Nov 2008
    Location
    not found
    Posts
    284
    Thanks
    0
    Thanked 53 Times in 51 Posts
    Your actual URL seems to be http://www.nicnok.net/html/gallery/gallery.html

    The only information you need is the last reported position of the mouse, which you poll periodically. http://scripterlative.com?cursordivscroll

  • #5
    New to the CF scene
    Join Date
    Jun 2009
    Posts
    3
    Thanks
    0
    Thanked 0 Times in 0 Posts
    Sorry about the url, I changed it after my initial post. As you may or may not be able to tell, I am very new to javascript. I copied and translated my code from Actionscript, and I appreciate the link, but I cannot see where it's solution lies. I can't figure out why Firefox will only recognize the event's property inside a onmousemove handler and ie won't recognize the .clientX at all. I appreciate what help I've been given so far tho, and only wish I had more to offer in return. Thanks guys.


  •  

    Posting Permissions

    • You may not post new threads
    • You may not post replies
    • You may not post attachments
    • You may not edit your posts
    •