I am trying to create a resizable div without using the jQuery interface library.
var myY = 0; var mouseDown = false; var originalHeight = 0; function resize(e){ if(mouseDown == true){ $("#cooldiv").height(originalHeight+e.pageY-myY); } } $(document).ready(function(){ $().mouseup(function(e){ myY = 0; mouseDown = false; originalHeight = 0; $().unbind("mousemove", resize); }); $("#resizeBar").mousedown(function(e){ myY = e.pageY; originalHeight = $("#cooldiv").height(); mouseDown = true; $().bind("mousemove", resize); }); });
...
<div id="cooldiv" style="width: 500px; height: 300px; background-color: #cccccc; position: relative;"> <div id="resizeBar" style="height: 10px; width: 500px; background-color: #aaaaaa; position: absolute; bottom: 0;"></div> </div>
The first size changes perfectly (i.e. mousedown, mousemove then mouseup), but at the subsequent (mousedown + mousemove) s, the browser tries to drag the entire divizeBar div instead of resizing its parent container correctly. In mouse mode, the div then starts resizing "cooldiv" to mousemove without the need for mousedown until the next mouse click.
These problems do not appear in Internet Explorer.
source share