JavaScript Using arrow keys to navigate grid of divs wount scroll overflown contents using arrow keys in excel,using arrow keys in javascript,

Here's a solution i found on stackoverflow this solution works for me except that when the contents of the div is overflown the contents do not scroll alongside the arrow keys, like scroll seems to be much slower after the 5 or 6 rows.

Please here's an updated jsFiddle of the answer above

var position = { x: 0, y: 0 };
var calendarMap = [];

$(document).ready(function () {
    $('.row').each(function () {
        calendarMap.push([]);
        $('.day, .date', this).each(function () {
            calendarMap[calendarMap.length - 1].push($(this));
        });
    });
    highlightCell();
});

$(window).on('keydown', function (e) {
    if (e.keyCode === 37) // left
        moveLeft();
    else if (e.keyCode === 38) // up
        moveUp();
    else if (e.keyCode === 39) // right
        moveRight();
    else if (e.keyCode === 40) // down
        moveDown();
    highlightCell();
});

function moveLeft() {
    position.x--;
    if (position.x < 0)
        position.x = 0;
}

function moveUp() {
    position.y--;
    if (position.y < 0)
        position.y = 0;
}

function moveRight() {
    position.x++;
    if (position.x >= calendarMap[0].length)
        position.x = calendarMap[0].length - 1;
}

function moveDown() {
    position.y++;
    if (position.y >= calendarMap.length)
        position.y = calendarMap.length - 1;
}

function highlightCell() {
    $('.day, .date').removeClass('selected');
    calendarMap[position.y][position.x].addClass('selected');
}
Answer:1

I am following this example for making a custom editable <span> using ngModelController: https://docs.angularjs.org/api/ng/type/ngModel.NgModelController#example What I want to do now is to be ...

I am following this example for making a custom editable <span> using ngModelController: https://docs.angularjs.org/api/ng/type/ngModel.NgModelController#example What I want to do now is to be ...

I have made a dropdown that appears on click on a button. Pretty simple, except for how I have to click twice to get the js function to execute. After I click it the first, it appears and disappears ...

I have made a dropdown that appears on click on a button. Pretty simple, except for how I have to click twice to get the js function to execute. After I click it the first, it appears and disappears ...

  1. having to click twice on everything
  2. having to click mouse twice

My application returns the relative positions between two lines and I want draw this lines with Javascript. The line is defined with a director vector, a point and is three dimension. Is there any ...

My application returns the relative positions between two lines and I want draw this lines with Javascript. The line is defined with a director vector, a point and is three dimension. Is there any ...

  1. drawing with elements of art
  2. drawing elements and principles
  3. drawing with elements and principles of art
  4. drawing that have elements of art
  5. drawing in elements

Firstly, sorry for my poor English. I'm learning AngularJS recently and I found that many of AngularJS's concept are very advanced especially the Directive. It's much like the Shadow DOM or Web ...

Firstly, sorry for my poor English. I'm learning AngularJS recently and I found that many of AngularJS's concept are very advanced especially the Directive. It's much like the Shadow DOM or Web ...