0

I am creating an image gallary using owl carousel and php.there mouse click event working perfectly but when click command over keyboard having problem skip one image on prev keyup only and only first time. which code are calling after keyup function when write that code inside that function working perfectly

 $(document.documentElement).keyup(function(event) {
        // handle cursor keys
        if (event.keyCode == 37) {
        $(".prev").click();
    });

      var prevkey = $(".prev");
    prevkey.unbind("click").click(function() {
    $(".reset").click();
        setTimeout(function() {
            $(".printable").load(function(){
            $(".owl-carousel").myfunction();
        });
    }, 200);
    curEle = $(".item.active").parent();
   //console.log(curEle);
    if(curEle.find(".item").attr("data-id")==0)
    {
    $(this).addClass("disabled");
    }
    else
    {
    $(this).removeClass("disabled");
    prevEle = curEle.prev();
    console.log(prevEle);
    prevEle.find(".item").addClass("active");
                                curEle.find(".item").removeClass("active");
                                prevEle.find(".printable").attr("src",prevEle.find(".printable").attr("data-src"));
        carousel.trigger("owl.prev");
        curEle.find(".printable").attr("src","");
    }
    });
Ashish Mishra
  • 165
  • 1
  • 1
  • 9

2 Answers2

1

Insert preventDefault() to avoid other events than yours...

$(document.documentElement).keyup(function(event) { 
    // handle cursor keys 
    event.preventDefault();
    if (event.keyCode == 37) { 
        $(".prev").click(); 
    }
});

EDIT check this answer if you're using IE8

Community
  • 1
  • 1
Jordi Castilla
  • 26,609
  • 8
  • 70
  • 109
0

try this using one will prevent a second call

$(".prev").one("click",function(){
//your stuff
});
Optimus
  • 2,200
  • 8
  • 37
  • 71