Programming Forums
User Name Password Register
 

RSS Feed
FORUM INDEX | TODAY'S POSTS | UNANSWERED THREADS | ADVANCED SEARCH

Reply
 
Thread Tools Display Modes
Old Sep 14th, 2006, 7:10 PM   #1
Jimbo
Battle Programmer
 
Jimbo's Avatar
 
Join Date: Feb 2006
Location: Bellevue, WA, USA
Posts: 763
Rep Power: 3 Jimbo is on a distinguished road
propagating mousemove events

For the site I'm currently working on, I'm trying to fix some JavaScript code that lets the user draw a box (a <div> with a border and transparent background) over an image. The box is resized via the onmousemove handler. It works by having the user click once, then move the mouse to another point (the opposite corner) and click again to pin the box down, if you will. The current code has equivalent onmousemove events defined for both the <img> and the <div> on top of it; the problem is that if the mouse moves slow enough (keeping the mouse coordinates inside the border), the user can make the <div> extend beyond the regions of the <img>.

What I would like to do is simply have the mousemove propagated to the <img> and then remove the handler from the <div>. This would restrict the box to being over the image no matter what, but if I just remove the handler, the mousemove event is stopped at by the <div> when the mouse backtracks, so the user can't shrink the box. The problem is that I don't know how to make the event propagate. I've spent a long time with google and nothing really says how to do what I want. Is there a way to do this?
Jimbo is offline   Reply With Quote
Old Sep 15th, 2006, 2:26 AM   #2
Arevos
Programming Guru
 
Arevos's Avatar
 
Join Date: Aug 2005
Location: England
Posts: 1,499
Rep Power: 5 Arevos is on a distinguished road
Why not just have a simple check to see if the mouse coordinates are still over the image before resizing the div? Prototype has a function that does just this, if I recall correctly.
Arevos is offline   Reply With Quote
Old Sep 15th, 2006, 3:05 AM   #3
Jimbo
Battle Programmer
 
Jimbo's Avatar
 
Join Date: Feb 2006
Location: Bellevue, WA, USA
Posts: 763
Rep Power: 3 Jimbo is on a distinguished road
I did that to check the width, but the image is not completely absolutely positioned (theImage.style.left is set but not theImage.style.top), so I don't know what range of vertical coordinates is. Unless there's a way to have the browser return that value without having to set it? And account for any scrolling that might occur?
Jimbo is offline   Reply With Quote
Old Sep 15th, 2006, 7:05 AM   #4
Arevos
Programming Guru
 
Arevos's Avatar
 
Join Date: Aug 2005
Location: England
Posts: 1,499
Rep Power: 5 Arevos is on a distinguished road
Check out the Prototype javascipt framework. It's widely used, available as a single js file, and adds a number of extensions to the basic Javascript library, including functions to handle forms, element positioning, classes and functional programming.

In your case, the Position.within function would seem to be the one to use. Perhaps something like:
javascript Syntax (Toggle Plain Text)
  1. if (!Position.within($('my_image_id'), event.x, event.y))
  2. // mouse cursor no longer within image with id of 'my_image_id'
Note that the above code isn't tested; it's just to give you an idea of what I mean.

Also note that $() is a wrapper around document.getElementById() provided by Prototype.
Arevos is offline   Reply With Quote
Old Sep 15th, 2006, 1:20 PM   #5
Jimbo
Battle Programmer
 
Jimbo's Avatar
 
Join Date: Feb 2006
Location: Bellevue, WA, USA
Posts: 763
Rep Power: 3 Jimbo is on a distinguished road
Thanks Arevos, that seems to be working perfectly
Jimbo is offline   Reply With Quote
Reply

Bookmarks

« Previous Thread in Forum | Next Thread in Forum »

Currently Active Users Viewing This Thread: 1 (0 members and 1 guests)
 
Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Forum Jump

Similar Threads
Thread Thread Starter Forum Replies Last Post
Detecting/Blocking Events in External Applications ZeeMan Visual Basic 0 Jun 28th, 2006 6:32 PM
Clone Node Events Eryk JavaScript and Client-Side Browser Scripting 2 Feb 24th, 2006 2:15 PM
question: usage of delagates and custom events melbolt C# 1 Oct 3rd, 2005 7:17 PM
How to handle keyboard events in an app containing ActiveX Controls ? George Giolfan Visual Basic .NET 0 Aug 7th, 2005 3:07 AM




DaniWeb IT Discussion Community
All times are GMT -5. The time now is 9:55 PM.

Powered by vBulletin® Version 3.7.0, Copyright ©2000 - 2008, Jelsoft Enterprises Ltd.
Copyright ©2007 DaniWeb® LLC