javascript - Need onclick to go full distance before click works again

前端 未结 6 2006
温柔的废话
温柔的废话 2021-01-19 10:20

I have this javascript function I use that when clicked goes a certain distance. This is used within a scroller going left to right that uses about 7 divs. My question is ho

6条回答
  •  迷失自我
    2021-01-19 11:06

    Use an automatic then call like this

    var isMoving = false;
    $(function () {  
    
      $("#right, #left").click(function () {
        if (isMoving) return;
        isMoving = true;
    
        var dir = this.id == "right" ? '+=' : '-=';
        $(".outerwrapper").stop().animate({ scrollLeft: dir + '251' }, 1000).then(function(){isMoving = false}());
      });
    
    });
    

提交回复
热议问题