I made the onkeydown function, which runs blocks of li elements horizontally, it works fine, but I need it when the first and last li blocks in focus with the left and right keys should be disabled.
Can anyone suggest a root path? 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; } }); } });
jsfiddle working link
jquery jquery-plugins jquery-selectors
matthewb
source share