Loop while mousedown?????

Collapse
This topic is closed.
X
X
 
  • Time
  • Show
Clear All
new posts
  • pleary@mbl.edu

    Loop while mousedown?????

    I am quite familiar with JavaScript and many other programming
    languages as I am a programmer for a living. However, I am having a
    heck of a time figuring out this problem. I would like to have a
    function loop as long as the mouse button is pressed. I am aware of the
    onMouseDown event to fire the loop, but I cann't figure out how to stop
    the loop with the onMouseUp event.

    I have tried setting a boolean value with the onMouseDown event, but
    once I release the mouse button, the boolean value cannot be changed
    until the loop is done. So, as the loop is waiting for the value to be
    changed, it becomes an infinite loop. Many people have offered
    suggestions, but none of them seem to work.

    Is there such a method as whileMouseDown, or is it possible to cancel a
    function with onMouseUp?

    This must be possible.... I am basically trying to scroll through an
    image hidden behind a division, much like scrolling through a web page.
    When you hold down the arrow key, it scrolls until you let go...

    I would greatly appreciate any help anyone can offer. I am using IE 6.0
    and I will include a code sample of what I have been doing:

    var ismousedown=0;

    document.onmous edown = mouseDown;
    document.onmous eup = mouseUp;

    function mouseDown()
    {
    ismousedown = 1;
    }
    function mouseUp()
    {
    ismousedown = 0;
    }
    function getMouseValue()
    {
    return ismousedown;
    }
    function checkMouse()
    {
    if(getMouseValu e == 0)
    {

    }else
    {
    moveDown();
    setTimeout("che ckMouse()",500) ;
    }
    }

  • Lee

    #2
    Re: Loop while mousedown?????

    pleary@mbl.edu said:[color=blue]
    >
    >I am quite familiar with JavaScript and many other programming
    >languages as I am a programmer for a living. However, I am having a
    >heck of a time figuring out this problem. I would like to have a
    >function loop as long as the mouse button is pressed. I am aware of the
    >onMouseDown event to fire the loop, but I cann't figure out how to stop
    >the loop with the onMouseUp event.[/color]

    Use setInterval() to start the loop onMouseDown and clearInterval() to stop it
    onMouseUp.

    Comment

    • Stephen Chalmers

      #3
      Re: Loop while mousedown?????


      <pleary@mbl.edu > wrote in message
      news:1105387611 .676786.319390@ f14g2000cwb.goo glegroups.com.. .
      <SNIP>
      [color=blue]
      >if(getMouseVal ue == 0)[/color]

      I'm not saying this will fix things, but if the above statement is an
      accurate transcript of your working code, I'm sure you'll see the problem.

      --
      S.C.



      Comment

      • RobG

        #4
        Re: Loop while mousedown?????

        pleary@mbl.edu wrote:[color=blue]
        > I am quite familiar with JavaScript and many other programming
        > languages as I am a programmer for a living. However, I am having a
        > heck of a time figuring out this problem. I would like to have a
        > function loop as long as the mouse button is pressed. I am aware of the
        > onMouseDown event to fire the loop, but I cann't figure out how to stop
        > the loop with the onMouseUp event.[/color]

        Have a read here, particularly the bit about event handlers.

        <URL:http://www.quirksmode. org/js/introevents.htm l>

        I think you want to fire the scroll onmousedown, then cancel it with
        onmouseup and maybe onmouseout also.

        Hope it helps :-)

        --
        Rob

        Comment

        Working...