SitePoint Sponsor

User Tag List

Results 1 to 5 of 5

Threaded View

  1. #1
    SitePoint Wizard
    Join Date
    Dec 2004
    Location
    At My Desk!!
    Posts
    1,642
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    Looping through an onMouseDown event

    Hey guys I have the following code, what this does is moves a div around the screen when a button is pressed, what I would like to do is be able to hold the button down and the div carries on moving, can someone please lend me a hand in modifying it.

    Thanks in advance

    HTML Code:
    </style>
    <script type='text/javascript'>
    window.onload = function()
    {
      var mvr = document.getElementById('mover');
      mvr.style.left = '400px';
      mvr.style.top = '300px';
      var i, panel = document.getElementById('panel');
      var btns = panel.getElementsByTagName('div');
      for (i = 0; i < btns.length; i++) {
        btns[i].onmouseover = btnOnClick;
      }
    }
    function btnOnClick()
    {
      var delta = 20;
      var mvr = document.getElementById('mover');
      var x = parseInt(mvr.style.left);
      var y = parseInt(mvr.style.top);
      switch (this.id) {
        case 'btnU':
          y -= delta;
          break;
        case 'btnR':
          x += delta;
          break;
        case 'btnD':
          y += delta;
          break;
        case 'btnL':
          x -= delta;
          break;
      } // end switch
      mvr.style.left = x + 'px';
      mvr.style.top = y + 'px';
    }
    </script>
    Last edited by webnoob; Dec 20, 2006 at 07:51.
    "Am I the only one doing ASP.NET in Delphi(Pascal)?"


Bookmarks

Posting Permissions

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