javascript - Issue with jQuery and auto-resizing textarea -


i have textareaexpander jquery function working, i'm having 1 little issue it.

when textarea large, removing text bottom of backspace or delete buttons causes focus move top of textarea, , cursor gets moved off screen. makes jarring edit large sections of text.

how function auto-resize textarea, without jumping around , hiding cursor in situation?

(function($) {     // jquery plugin definition     $.fn.textareaexpander = function(minheight, maxheight) {         var hcheck = !($.browser.msie || $.browser.opera);         // resize textarea         function resizetextarea(e) {             // event or initialize element?             e = e.target || e;             // find content length , box width             var vlen = e.value.length, ewidth = e.offsetwidth;             if (vlen != e.vallength || ewidth != e.boxwidth) {                 if (hcheck && (vlen < e.vallength || ewidth != e.boxwidth)) e.style.height = '0px';                 var h = math.max(e.expandmin, math.min(e.scrollheight, e.expandmax));                 e.style.overflow = (e.scrollheight > h ? 'auto' : 'hidden');                 e.style.height = h + 'px';                 e.vallength = vlen;                 e.boxwidth = ewidth;             }             return true;         };         // initialize         this.each(function() {             // textarea?             if (this.nodename.tolowercase() != 'textarea') return;             // set height restrictions             var p = this.classname.match(/expand(\d+)\-*(\d+)*/i);             this.expandmin = minheight || (p ? parseint('0'+p[1], 10) : 0);             this.expandmax = maxheight || (p ? parseint('0'+p[2], 10) : 99999);             // initial resize             resizetextarea(this);             // 0 vertical padding , add events             if (!this.initialized) {                 this.initialized = true;                 $(this).css('padding-top', 0).css('padding-bottom', 0);                 $(this).bind('keyup', resizetextarea).bind('focus', resizetextarea);             }         });         return this;     }; })(jquery); // initialize expanding textareas jquery(document).ready(function() {     jquery('textarea[class*=expand]').textareaexpander(); }); 

you can see issue here deleting text bottom of textarea: http://jsfiddle.net/bmwce/1/

thanks!

ended finding better function use instead of 1 above. doesn't seem have of problems of other one.

you can find details on here: auto resizing textarea link down jquery


Comments

Popular posts from this blog

java.util.scanner - How to read and add only numbers to array from a text file -

rewrite - Trouble with Wordpress multiple custom querystrings -