// Handle the mouse move event on the parent div $( "div:first" ).mousemove(function(e) { // calculate the mouse position relative to the div element position on the page var x = e.pageX - $(this).offset().left; $('.divider').css('left', x); $('.left').css('width', x); });
To make it work, I also had to tweak the CSS:
.left { left: 0px; z-index: 1; }
Demo: http://codepen.io/anon/pen/epwQLr
source share