Record the MouseDown location, check witht eh MOuseUp location and if same show Menu
Hello Everyone,
I'm new still at Javascript and I'm trying to do something like this:
Code:
table.onmousedown {
f_pos_x = //Set the First X Location
f_pos_y = //Set the first Y location
});
table.onmousedown {
s_pos_x = //Set the Second X Location
s_pos_y = //Set the Second Y Location
if ("f_pos_x" == "s_pos_x" && "f_pos_y" == "s_pos_y") {
set_tab('new2_tabs', 'tile_options');
});
});
I have a click and drag map, where as if they click on a tile, I would like the menu to show, but I was havign the problem where if you click and drag again this menu would change so I need to record the mousedown location and check with the mouse up location and if they are the same then show the new menu.
Comparing the coords before and after may prove unreliable, but I can't be certain of this. Another possibility is to set a flag/variable onmousedown and clear it onmousemove.. But I'm just speculating
__________________
"I'm here to save your life. But if I'm going to do that, I'll need total uninanonynymity." Me Myself & Irene.
Validate your HTML and CSS
You don't *REALLY* care if the mouse has move 2 pixels, right? And that's very likely to happen with a human hand controlling the mouse.
So, instead, just check to see if the mouse is in the SAME TILE!
Like this:
Code:
// set up all the cells:
for ( var r = 0; r < theMap.length; ++r )
{
var row = theMap[r];
var tr = tbl.insertRow(-1);
for ( var c = 0; c < row.length; ++c )
{
var cell = tr.insertCell(-1);
cell.id = (theMap.length - r - 2) + ":" + (c+1-5);
cell.className = classes[row.charAt(c)];
cell.onmouedown = cellClickStart;
cell.onmouseup = cellClickEnd;
}
}
...
var whereButtonDown = null;
function cellCickStart( )
{
whereButtonDown = this;
}
function cellClickEnd( )
{
var bDown = whereBUttonDown;
whereBUttonDown = null; // RESET IT!
if ( bDown != this ) /* have we moved to a different tile? */
{
/* yes...so treat it as a drag: */
mouseDragged( bDown, this );
return;
}
// still in same cell, so just treat as a click & show menu:
clk.innerHTML = this.id;
typ.innerHTML = this.className;
pop.style.display = "block";
}
function mouseDragged( fromCell, toCell )
{
.. you can write this ..
}
New/changed stuff in red.
__________________
An optimist sees the glass as half full.
A pessimist sees the glass as half empty.
A realist drinks it no matter how much there is.
If, as stated, this is a click and drag map them presumably the target-tile will be the same for both mouseup and mousedown.
You might consider my earlier suggestion:
Code:
var justClick = false;
someElement.onmousedown = function () {
justClick = true;
}
someElement.onmousemove = function () {
justClick = false;
}
someElement.onmouseup = function () {
if (justClick) {
// show menu..
return;
}
}
Although it's hard to be certain without further information.
__________________
"I'm here to save your life. But if I'm going to do that, I'll need total uninanonynymity." Me Myself & Irene.
Validate your HTML and CSS
Ahh...good point. If it's truly a drag. But I don't *THINK* it is. I think he's really trying to use this to move a playing piece from one tile to the next. Well, I guess we shall see.
__________________
An optimist sees the glass as half full.
A pessimist sees the glass as half empty.
A realist drinks it no matter how much there is.