简体   繁体   中英

on trigger click event script called 2 time in first attempt

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","");
    }
    });

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

try this using one will prevent a second call

$(".prev").one("click",function(){
//your stuff
});

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM