Associate
- Joined
- 11 Oct 2008
- Posts
- 268
Hey guys. Happy new year!
I'm slowly getting my head around javascript, with a lot of help from this forum![Stick Out Tongue :P :P](/styles/default/xenforo/vbSmilies/Normal/tongue.gif)
I am using this code to listen out for touches which is working well now.
It seems like I am repeating myself quite a lot. Is there a better technique I could be using for the following?
Thanks![Big Grin :D :D](/styles/default/xenforo/vbSmilies/Normal/biggrin.gif)
I'm slowly getting my head around javascript, with a lot of help from this forum
![Stick Out Tongue :P :P](/styles/default/xenforo/vbSmilies/Normal/tongue.gif)
I am using this code to listen out for touches which is working well now.
It seems like I am repeating myself quite a lot. Is there a better technique I could be using for the following?
Code:
function onload(){
var left= document.getElementById('left')
left.addEventListener('touchstart', function (){ move('left') }, false);
left.addEventListener('touchend', function (){ move('left') }, false);
var right= document.getElementById('right')
right.addEventListener('touchstart', function (){ move('right') }, false);
right.addEventListener('touchend', function (){ move('right') }, false);
var up= document.getElementById('up')
up.addEventListener('touchstart', function (){ move('up') }, false);
up.addEventListener('touchend', function (){ move('up') }, false);
var down= document.getElementById('down')
down.addEventListener('touchstart', function (){ move('down') }, false);
down.addEventListener('touchend', function (){ move('down') }, false);
}
Thanks
![Big Grin :D :D](/styles/default/xenforo/vbSmilies/Normal/biggrin.gif)