Sykoi
02-08-2006, 07:45 PM
The title says it all, albeit some details: I'm currently attempting to create an overflowed div that will contain thousands of images and controllable by the keyboard... What for? You may never know! :D (Its honestly not a shot in the dark, its pretty obvious what its for and I will be sharing bits and pieces on this forum, if I ever manage to get it to work)
Right now I'm attempting to use some code I found, which uses window.event.keyCode, now this in itself is a problem, but I will discuss it later as my main problem, the problem that has got me pulling my hair out, needs attending to: I can't find an actual, good way, that works in all browsers, to scroll the contents of a div (With overflow:hidden)! I've tried 'posTop' (Microsoft and their custom style commands! BAH!), and I've tried marginTop/Top... Neither work more than once, as once you call one of these commands - it automatically changes the integer to a string... And as we all know, you can't increment strings :(
So I'm at my wit's end, what in gods name do I do? Do I spend hours writing a possibly complex function to take off the 'px' and change the string value back to an integer every time I need to? Or is there an obvious answer that I’m completely missing after my mindless hours toiling over w3schools.com’s list of CSS commands?
And now moving on to my not so pressing matter: How do I accept keyboard input, inside a div, and call functions from certain keys - while making sure this works in all browsers?
My code:
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1" />
<title>Untitled Document</title>
<script language="javascript">
document.onkeypress = keyhandler;
function keyhandler(e) {
if (document.layers)
Key = e.which;
else
Key = window.event.keyCode;
/*if (Key != 0)
alert("Key pressed! ASCII-value: " + Key);*/
if (Key == 115) {
alert(document.getElementById('map').style.marginTop);
//document.getElementById('map').style.posTop = document.getElementById('map').style.posTop - 10;
document.getElementById('map').style.marginTop = document.getElementById('map').style.marginTop - 10;
}
}
</script>
</head>
<body>
<div style="overflow:hidden; width: 500px; height: 500px;">
<div style="margin-top: 100px;" id="map">
<img src="world-time-zone-2.jpg" />
</div>
</div>
</body>
</html>
Well, thank you in advanced for attempting to help me.
Right now I'm attempting to use some code I found, which uses window.event.keyCode, now this in itself is a problem, but I will discuss it later as my main problem, the problem that has got me pulling my hair out, needs attending to: I can't find an actual, good way, that works in all browsers, to scroll the contents of a div (With overflow:hidden)! I've tried 'posTop' (Microsoft and their custom style commands! BAH!), and I've tried marginTop/Top... Neither work more than once, as once you call one of these commands - it automatically changes the integer to a string... And as we all know, you can't increment strings :(
So I'm at my wit's end, what in gods name do I do? Do I spend hours writing a possibly complex function to take off the 'px' and change the string value back to an integer every time I need to? Or is there an obvious answer that I’m completely missing after my mindless hours toiling over w3schools.com’s list of CSS commands?
And now moving on to my not so pressing matter: How do I accept keyboard input, inside a div, and call functions from certain keys - while making sure this works in all browsers?
My code:
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1" />
<title>Untitled Document</title>
<script language="javascript">
document.onkeypress = keyhandler;
function keyhandler(e) {
if (document.layers)
Key = e.which;
else
Key = window.event.keyCode;
/*if (Key != 0)
alert("Key pressed! ASCII-value: " + Key);*/
if (Key == 115) {
alert(document.getElementById('map').style.marginTop);
//document.getElementById('map').style.posTop = document.getElementById('map').style.posTop - 10;
document.getElementById('map').style.marginTop = document.getElementById('map').style.marginTop - 10;
}
}
</script>
</head>
<body>
<div style="overflow:hidden; width: 500px; height: 500px;">
<div style="margin-top: 100px;" id="map">
<img src="world-time-zone-2.jpg" />
</div>
</div>
</body>
</html>
Well, thank you in advanced for attempting to help me.