https://jsfiddle.net/mzx79os2/13/
var $descriptionTextarea = $("textarea");
var $char_count = $(".char_count");
var textMax = 5;
var animation, animationInProcess;
$char_count.html(textMax + ' characters remaining');
function blinkStart(selfCharCounter) {
console.log('run blink');
animationInProcess = true;
animation = setInterval(function(selfCharCounter){
if(!animationInProcess){
blinkStop(selfCharCounter)
return;
}
$(selfCharCounter).fadeOut(500).fadeIn(500);
}, 500, selfCharCounter);
};
function blinkStop(selfCharCounter){
console.log('stop blink');
$(selfCharCounter).stop(true, true).show();
clearInterval(animation);
};
$descriptionTextarea.on("keyup",function(e){
e.stopPropagation();
var textLength = $(this).val().length;
var textRemaining = textMax - textLength;
var selfCharCounter = $(this).next();
if(textRemaining <= 0){
(!animationInProcess) && blinkStart(selfCharCounter);
selfCharCounter.css("color","red");
}else{
animationInProcess = false;
selfCharCounter.css("color","");
}
selfCharCounter.html(textRemaining + ' characters remaining');
});
請您編輯我的小提琴鏈接和更新there..and解釋我在短暫的 – Chandrakant
請加解釋。 – Rajesh
有一刻,我改寫了代碼 –