For example, if I have a grid of boxes, and each has an ID like coordinates (ie $w(“#1x1), $w(”#1x2), $w("#1x3) and so on) and I want to be able to slect and change the colour of the next box after the user has pressed up, down, left or right, like a game.
Is this possble? I can easily get the right coordinates for the directional clicks, but I do not know how to select an element with a variable.
Any help is greatly appreciated.
I want to be able to slect and change the colour of the next box after the user has pressed up, down, left or right, like a game.
As i know there is no way to get keyboard support in on wix-pages.
The only supported keyboard functions are…
https://www.wix.com/velo/reference/$w/keyboardevent
So as you can see, there is no support for → LEFT, RIGHT, UP or DOWN keypress.
Yes your idea with the x-y-axis method inside the ID definition of each element could work…
X and Y-axis navigation…custom mode…
$w('#'+x+'element'+y)
Your buttons on the page…
$w(‘#1element1’)
$w(‘#1element2’)
$w(‘#1element3’)
$w(‘#1element4’)
$w(‘#1element5’)
$w(‘#2element1’)
$w(‘#2element2’)
$w(‘#2element3’)
$w(‘#2element4’)
$w(‘#2element5)
$w(’#3element1’)
$w(‘#3element2’)
$w(‘#3element3’)
…and so on…
…but still the problem that you have no pissibility to get the KEYBOARD_KEYS of (left, right, up and down).
But of course there is always a opened backdoor to be found…
And yes, there is a way out of this issue, called → html-component, or custom element.
You will need it to be able to generate your KEY-CONTROL.
But since you are already using an HTML-COMPONENT → you also can create your whole menu-navigation or even whole game inside HTML-component or custom element.
CORRECTION: Forget about HTML-COMPONENT again.
I did not see this one…
let key = event.key;// "A"
So you don’t need a HTML-Component!!! My fault, sorry!