我正在使用HTML5数字字段来设置顶部位置,当数字字段增加时[内部数字字段]我需要增加顶部值,反之亦然,如果它减少则需要减少最高值。
$("#font_y_pos").change(function(event) {
var obj = canvas.getActiveObject();
if (!obj)
return;
var y_pos = obj.getTop() - $(this).val();
obj.set('top', y_pos);
canvas.renderAll();
});
但我怎么能区分这2个事件?如果价值增加或减少?
答案 0 :(得分:1)
// before the first click on the field, store the original value
elm.onfocus=function () {elm.prevValue = elm.value; };
elm.onclick= function () {
// when clicking the field, write to log the diff between current value and previous
console.log ((elm.prevValue - elm.value)>0); // output=true/false depending on your direction
// store current value as previous for next iteration
elm.prevValue = elm.value;
};