Jquery Disable Next button until animation finishes

有些话、适合烂在心里 提交于 2019-12-07 13:28:26
$(function(){
    $("#previous").bind("click", Previous);
    $("#next").bind("click", Next);
});

function DoAnimation() {
    $("#previous,#next").unbind("click");
    $('#id').animate(
        complete: function() {
            $(this).after('<div>Animation complete.</div>');
            $("#previous").bind("click", Previous);
            $("#next").bind("click", Next);
        }
    });
}

function Previous() { }
function Next() { }
Valentin Kantor

one more technique:

$(".next,.prev").click(function(){
    if ($('#my_animated_elelement').is(':animated'))
    {
        return false;
    }
})

I guess you have javascript calls for the images onclick's, use a variable MyApp.IgnoreNextPrevClicks to flag whether the onclick handlers do execute or not.

MyApp={}
MyApp.IgnoreNextPrevClicks=false;
MyApp.PrevClick=function() {
    if(MyApp.IgnoreNextPrevClicks) return;
    //real work goes here
}

now before calling the jquery animator, set MyApp.IgnoreNextPrevClicks to true, and set it back to false after the animation ends (use jquery animation callback).

function btn() {
   $('#btn').one('click', function(){
     //call your animation function here.

     setTimeout(btn, animation duration);
  });
}
$('#mybtn').attr("disabled","disabled"); // to Disable Button

$('#mybtn').removeAttr("disabled"); // to Enable Disabled button
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!