How to avoid executing .animate() jquery function for some DOM elements

50 Views Asked by At

I am modifying chessboard.js code. In this library .animate() function is called for every piece that is moved by user:

var opts = {
    duration: config.snapSpeed,
    complete: onAnimationComplete
  }
$draggedPiece.animate(targetSquarePosition, opts)

I want .animate() to not work for some pieces, so I modified code:

if(!isEmptyTargetSquare && !doesTargetPieceDie(sourceSquareId,targetSquareId)) {
    $draggedPiece.remove()
    $draggedPiece.stop()
}
else {
  $draggedPiece.animate(targetSquarePosition, opts)
}

This only works temporarily. The first time the control goes to if condition and everything works fine. Then when next piece is moved the else condition is executed and jQuery.fx.tick() is executed twice. When the jQuery.fx.tick() is executed the second time , the work done by if condition is undone. I am using chessboard.js with chess.js .

I was trying to modify chess program by assigning levels to pieces. If level of the attacking piece is less than target piece, the attacking piece would be removed.

0

There are 0 best solutions below