后台主页,布局如下图
拖动栏是个div,我要的功能是单击拖动栏后鼠标向右移动,左侧面积变大,右侧面积变小,向左移动反之。但我实现的效果是拖动栏移动缓慢,且拖动时鼠标无法离开div离开后就拖不动,gif图如下
想请教下各路大神,有没有什么好的方案能快速拖动,js代码如下
var mousex = 0;
var divLeft;
$('.move-div').mousedown(function (e) {
var offset = $(this).offset();
divLeft = parseInt(offset.left, 10);
mousex = e.pageX;
$(this).bind('mousemove', dragElement);
});
function dragElement(event) {
var left = divLeft + (event.pageX - mousex);
var thirdMarginLeft = $(this).width() + left; //前2个div的宽度
var thirdWidth = screen.width - $(this).width() - left; //第3个div的宽度
$(this).css({ 'left': left + 'px', 'position': 'absolute' });
$(this).prev(".folding-div").css({ 'width': left+"px" });
$(this).next(".iframe-div").css({ "margin-left": thirdMarginLeft +"px", "width": thirdWidth + "px","position":"absolute"});
return false;
}
$(document).mouseup(function () {
$('.move-div').unbind('mousemove');
});