Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8946173
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 15, 20262026-06-15T12:26:32+00:00 2026-06-15T12:26:32+00:00

I have made a onkeydown function which runs li elements blocks horizontally it runs

  • 0

I have made a onkeydown function which runs li elements blocks horizontally it runs perfectly but i need when the first and last li blocks in focus the left and right keys should get disable.

could anyone suggest a corrent way? Thanx in advance !!!

$(document).ready(function() {
    var winht = $(window).height();
    var contUl = $('.content ul').children('li').size();
    var widLi = $('.content ul li').width();
    var contUlAndLI = contUl * widLi;
    var leftIndex = $('.content ul').css('left','0');
    $('.content ul').width(contUlAndLI);
    $('#frame').height(winht);

$("body").keydown(function(e) {

  if(e.keyCode == 37) { // left
    $(".content ul").animate({
      left: "-=980"
    });
  }
  else if(e.keyCode == 39) { // right
    $(".content ul").animate({
      left: "+=980"
    });
  }

});

if( leftIndex == 0){

    $("body").keydown(function(e) {

        if(e.keyCode == 39){ // right
            //event.preventDefault();
            return false;
            }

        });
  }

});

the working reference is jsfiddle

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-15T12:26:33+00:00Added an answer on June 15, 2026 at 12:26 pm

    I did it by using a counter the value of which is checked each time the user presses left or right. The counter is simply the number of li elements inside the ul tag.

    var ulCount = $('.content li').length - 1;
    var i = 0;
    

    Then only run the animation if we’re within the values of the counter:

    if(e.keyCode == 37) { // left
        if (i < ulCount) {
            i++;
            $(".content ul").animate({
              left: "-=980"
            });
        }
    }
    else if(e.keyCode == 39) { // right
        if (i > 0) {
            i--;
            $(".content ul").animate({
                left: "+=980"
            });
        }
    }
    

    I updated the jsFiddle too.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have made this game for Mac OS, but I realised that i need
I have made a cart and the cart has remove item button, but the
I have made an iphone application like flip cards in which values of cards
I have made my own exception class which derives from runtime_error and is getting
I have made an mvc3 application with Windows Authentication. Everything works fine but I
I have made a script to intimate the admin the list of module need
I have made this sandbox test: <html> <head> <title>whatever</title> <script type=text/javascript> function myLittleTest() {
I have made my own custon vtype which performs an ajax request to check
I have made a file called time.hs . It contains a single function that
I have made my Actor , but I am unclear on how to take

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.