I’m basically looking to duplicate the functionality of the draggable resize function of the textareas here on SO.
I know SO uses the jQuery plugin TextAreaResizer to accomplish this, but I want to use straight vanilla javascript so that I can learn how it actually works.
Well, here are the basic steps you will need to take:
Remove targeted
textareafrom the DOMCreate a
divPut the removed
textareainto the newly createddivand style it so it always takes all available area of thedivAdd an element for the drag handle and style it (probably also a
div)Attach
onmousedownandonmousemoveevent handlers to the drag handle element and reinstert the wrapperdivinto the DOMOn
mousedownevent, record the mouse coordinatesOn
mousemoveevent get the current mouse coordinates and calculate the delta with the previously memorised coordinatesSet the wrapper
divsize to its current size PLUS the deltas that you calculated (when deltas are negative, the size will reduce)That’s the basic steps you need to take, but there is a bit of detail that you will need to work out.