我的问题是,值在每个鼠标注册事件中传递给函数所以拖动和调整大小并不正确。
所以我写了像
这样的东西var value_ = 1;
div_mainscale.onmousedown = function(event) {
var mouseCoords = getCoords(event);
startX = mouseCoords.x - offset[0];
startY =1 ;//mouseCoords.y - offset[1];
rect = mainscale.rect(startX, startY);
document.onmousemove = doDraw;
rect.attr({fill: 'rgba(255, 6, 6, 0.41)', stroke: 'red'});
value_ = 1;
};
if(($(document).onmouseup) && (value_ == 1)) // here i make mistake
{
selectable_area(width,startX);
rect.remove();
}
而不是此代码
document.onmouseup = function() {
if(rect)
{
selectable_area(width,startX);
rect.remove();
}
document.onmousemove = null;
};
但if(($(document).onmouseup) && (value_ == 1))
这种情况不满意?我该如何解决我的问题?
答案 0 :(得分:1)
$(document).on("mouseup" , function(e) {
if (value_ == 1) {
value_ = 0;
selectable_area(width,startX);
rect.remove();
}
});
答案 1 :(得分:0)
$(document).mouseup(function(e) {
if (value_ == 1) {
selectable_area(width, startX);
rect.remove();
}
});
尝试以上代码为我工作