Js Keyeingabe + Animate Problem

01/27/2020 02:45 Cc_Cc_Cc#1
Guten Tag,

ich habe eine Textarea und wenn man mehr als 5 Zeichen eingibt soll die Höhe um 100px steigen. Klappt auch , aber wenn ich jetzt mal sehr sehr schnell etwas eingebe macht er die höhe 2x oder 3x plus 100px. Also er führt dann den Animate Befehl 2-3x aus, dann ist meine Area Box nicht um 100px gestiegen sondern um 200-300px. Woran liegt das?

PHP Code:
            $('.comment-area-text').on('keyup', function(e) {
            
                var 
data = $(this).val();
                
                if(
data.length 5) {
                    
                    if($(
'.comment-area-text').height() === 19) {
                    
                        $(
'.comment-area-text').animate({
                            
"height":"+=100px"
                        
}, 500);
                
                        
                    }
                    
                }
}); 
01/27/2020 05:40 elmarcia#2
Quote:
Originally Posted by Cc_Cc_Cc View Post
Guten Tag,

ich habe eine Textarea und wenn man mehr als 5 Zeichen eingibt soll die Höhe um 100px steigen. Klappt auch , aber wenn ich jetzt mal sehr sehr schnell etwas eingebe macht er die höhe 2x oder 3x plus 100px. Also er führt dann den Animate Befehl 2-3x aus, dann ist meine Area Box nicht um 100px gestiegen sondern um 200-300px. Woran liegt das?

PHP Code:
            $('.comment-area-text').on('keyup', function(e) {
            
                var 
data = $(this).val();
                
                if(
data.length 5) {
                    
                    if($(
'.comment-area-text').height() === 19) {
                    
                        $(
'.comment-area-text').animate({
                            
"height":"+=100px"
                        
}, 500);
                
                        
                    }
                    
                }
}); 
That weird behaviour is because your animation is called multiple times before finishing.

You can solve this problem using .stop(clearQueue,goToEnd), use the params it works best for you


If you want a dynamic box, then u need to create a function that calculates the size of the box
01/27/2020 16:27 Cc_Cc_Cc#3
Thank you its works !