var dragging = false;
var iX, iY ,rightw ,bottom;
$("#chatstage").on('mousedown','.currentbottom',function(e) {
rightw = parseInt($("#chatstage").css('right'));bottom = parseInt($("#chatstage").css('bottom'));
dragging = true;
iX = e.clientX ;
iY = e.clientY;
this.setCapture && this.setCapture();
return false;
});
$("#chatstage").on('mousemove','.currentbottom',function(e) {
if (dragging) {
var e = e || window.event;
var oX = rightw - (e.clientX - iX) ;
var oY = bottom -(e.clientY - iY);
$("#chatstage").css({"right":oX + "px", "bottom":oY + "px"});
return false;
}
});
$("#chatstage").on('mouseup','.currentbottom',function(e) {
dragging = false;
e.cancelBubble = true;
});
该代码的效果是相对于右下角进行定位,实际开发环境需要根据实际情况来计算最终oX和oY的像素。