所以我有这个JS程序:
http://codepen.io/anon/pen/avgQVa
$('.divider').draggable({
axis: 'x',drag: function(e,ui) {
$('.right').width(100 - ui.position.left);
$('.yellow').css('right',ui.position.left);
}
});
最佳答案
// 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);
});
为了使它工作,我不得不调整CSS:
.left {
left: 0px;
/* This makes the left div render "above" the others,so when we change its width it shows up */
z-index: 1;
}