I've asked this question before, and the responses told me what I knew I needed to do but didn't provide an example, so I haven't figured out a solution yet.
I've got an initial div called "container" which is a height:100% width:100%
image of an Oklahoma map. The idea is that when the user clicks a certain section of the map (for this example, the panhandle), the div is toggled to a div which is the panhandle image. I determine where the user clicks by knowing the pixel location of the mouse when it clicks.
The problem is, pixel values are different for different size screens. I've been told that in order to scale my calculations for where the user clicks based on their screen size, I need to:
scale every value before you compare it. Multiply every x by your canonical width and divide by the actual width and do the same with y and height.
I'm confused by "multiply every x by your canonical width and divide by the actual width." I went ahead and tried scaling anyways. I found that the first edge of the panhandle is 3.1% away from the left side of the screen and the farthest edge is 35.7% away from the left side of the screen. I have the following code:
$("#container").click(function(e)
{
var x = event.pageX;
var y = event.pageY;
// Variables for area of pan handle
/* These variables do not seem to work yet */
var xScale1 = 0.031*x;
var xScale2 = 0.357*x;
if(x >= xScale1 && x "less-than"= xScale2)
{
alert("You clicked the panhandle!");
}
}
This should pop-up an alert when I click within the horizontal confinements of the panhandle, but nothing is happening. I do notice that I am not dividing any of my values by "actual width". Could someone please provide an example of how to "multiply every x by your canonical width and divide by the actual width"?