First: - add a div container to check mousemove
<div id="content-div"> <div id="left-panel">f</div> <div id="drag-bar">f</div> <div id="right-panel">f</div> </div>
Second: - add the mousemove event to the div container
var movebar = false; $('#drag-bar').mousedown(function(e){ movebar = true; }); $('#drag-bar').mouseup(function(e){ movebar = false; }); $('#content-div').mousemove(function(e){ if(movebar) { var x = e.pageX; $('#left-panel').css({'width': x+'px'}); $('#right-panel').css({'margin-left': (x+5)+'px'}); } });
source share