Checked out other posts, no help...
I'm using asdw to move an object around within a limited space. I'm trying to figure out how to allow the object to move around while the key is pressed, without the momentary delay at the beginning.
Thanks...
$(document).ready(function(){
var longitude = 0;
var latitude = 0;
$('body#sense').keypress(function(){
if(event.which == 65 || event.which == 97){
// Left
if(longitude != 0){
longitude = longitude + 10;
$('img#map').css('margin-left', longitude);
}
}
else (event.which == 68 || event.which == 100){
// Right
if(longitude > -200){
longitude = longitude - 10;
$('img#map').css('margin-left', longitude);
}
}
});
});
The web page
<body id="sense">
<h2><center>Use your 'asdw' keys to move the map around</center></h2>
<div id="box">
<img id="map" src="http://www.toronto.ca/culture/victoria-square/images/ch0/Victoria-Square-map-t.gif" alt="" />
</div>
</body>
The holding the image has a set width and height, both smaller than the image. The is set to overflow:hidden, so the javascript moves the image around within the div so different parts are visible.
The CSS
div#box {
margin:0px auto;
width:225px;
height:225px;
overflow:hidden;
}
div#box img {
}