mirror of
https://github.com/konvajs/konva.git
synced 2025-06-28 15:23:44 +08:00
applying event throttling logic to mousemove and touchmove only
This commit is contained in:
parent
3c72f8240b
commit
a29d1520ae
54
dist/kinetic-core.js
vendored
54
dist/kinetic-core.js
vendored
@ -2005,22 +2005,11 @@ Kinetic.Stage.prototype = {
|
|||||||
|
|
||||||
return false;
|
return false;
|
||||||
},
|
},
|
||||||
_handleStageEvent: function(evt) {
|
|
||||||
var throttle = this.attrs.throttle;
|
|
||||||
var date = new Date();
|
|
||||||
var time = date.getTime();
|
|
||||||
var timeDiff = time - this.lastEventTime;
|
|
||||||
var tt = 1000 / throttle;
|
|
||||||
|
|
||||||
if(timeDiff >= tt) {
|
|
||||||
this._handleStageEventContinue(evt);
|
|
||||||
}
|
|
||||||
},
|
|
||||||
/**
|
/**
|
||||||
* handle incoming event
|
* handle incoming event
|
||||||
* @param {Event} evt
|
* @param {Event} evt
|
||||||
*/
|
*/
|
||||||
_handleStageEventContinue: function(evt) {
|
_handleStageEvent: function(evt) {
|
||||||
var date = new Date();
|
var date = new Date();
|
||||||
var time = date.getTime();
|
var time = date.getTime();
|
||||||
this.lastEventTime = time;
|
this.lastEventTime = time;
|
||||||
@ -2083,9 +2072,20 @@ Kinetic.Stage.prototype = {
|
|||||||
}, false);
|
}, false);
|
||||||
|
|
||||||
this.content.addEventListener('mousemove', function(evt) {
|
this.content.addEventListener('mousemove', function(evt) {
|
||||||
that.mouseUp = false;
|
/*
|
||||||
that.mouseDown = false;
|
* throttle mousemove
|
||||||
that._handleStageEvent(evt);
|
*/
|
||||||
|
var throttle = that.attrs.throttle;
|
||||||
|
var date = new Date();
|
||||||
|
var time = date.getTime();
|
||||||
|
var timeDiff = time - that.lastEventTime;
|
||||||
|
var tt = 1000 / throttle;
|
||||||
|
|
||||||
|
if(timeDiff >= tt) {
|
||||||
|
that.mouseUp = false;
|
||||||
|
that.mouseDown = false;
|
||||||
|
that._handleStageEvent(evt);
|
||||||
|
}
|
||||||
}, false);
|
}, false);
|
||||||
|
|
||||||
this.content.addEventListener('mouseup', function(evt) {
|
this.content.addEventListener('mouseup', function(evt) {
|
||||||
@ -2094,11 +2094,10 @@ Kinetic.Stage.prototype = {
|
|||||||
that._handleStageEvent(evt);
|
that._handleStageEvent(evt);
|
||||||
that.clickStart = false;
|
that.clickStart = false;
|
||||||
}, false);
|
}, false);
|
||||||
/*
|
|
||||||
this.content.addEventListener('mouseover', function(evt) {
|
this.content.addEventListener('mouseover', function(evt) {
|
||||||
that._handleStageEvent(evt);
|
that._handleStageEvent(evt);
|
||||||
}, false);
|
}, false);
|
||||||
*/
|
|
||||||
|
|
||||||
this.content.addEventListener('mouseout', function(evt) {
|
this.content.addEventListener('mouseout', function(evt) {
|
||||||
// if there's a current target shape, run mouseout handlers
|
// if there's a current target shape, run mouseout handlers
|
||||||
@ -2125,8 +2124,19 @@ Kinetic.Stage.prototype = {
|
|||||||
}, false);
|
}, false);
|
||||||
|
|
||||||
this.content.addEventListener('touchmove', function(evt) {
|
this.content.addEventListener('touchmove', function(evt) {
|
||||||
evt.preventDefault();
|
/*
|
||||||
that._handleStageEvent(evt);
|
* throttle touchmove
|
||||||
|
*/
|
||||||
|
var throttle = that.attrs.throttle;
|
||||||
|
var date = new Date();
|
||||||
|
var time = date.getTime();
|
||||||
|
var timeDiff = time - that.lastEventTime;
|
||||||
|
var tt = 1000 / throttle;
|
||||||
|
|
||||||
|
if(timeDiff >= tt) {
|
||||||
|
evt.preventDefault();
|
||||||
|
that._handleStageEvent(evt);
|
||||||
|
}
|
||||||
}, false);
|
}, false);
|
||||||
|
|
||||||
this.content.addEventListener('touchend', function(evt) {
|
this.content.addEventListener('touchend', function(evt) {
|
||||||
|
4
dist/kinetic-core.min.js
vendored
4
dist/kinetic-core.min.js
vendored
File diff suppressed because one or more lines are too long
54
src/Stage.js
54
src/Stage.js
@ -551,22 +551,11 @@ Kinetic.Stage.prototype = {
|
|||||||
|
|
||||||
return false;
|
return false;
|
||||||
},
|
},
|
||||||
_handleStageEvent: function(evt) {
|
|
||||||
var throttle = this.attrs.throttle;
|
|
||||||
var date = new Date();
|
|
||||||
var time = date.getTime();
|
|
||||||
var timeDiff = time - this.lastEventTime;
|
|
||||||
var tt = 1000 / throttle;
|
|
||||||
|
|
||||||
if(timeDiff >= tt) {
|
|
||||||
this._handleStageEventContinue(evt);
|
|
||||||
}
|
|
||||||
},
|
|
||||||
/**
|
/**
|
||||||
* handle incoming event
|
* handle incoming event
|
||||||
* @param {Event} evt
|
* @param {Event} evt
|
||||||
*/
|
*/
|
||||||
_handleStageEventContinue: function(evt) {
|
_handleStageEvent: function(evt) {
|
||||||
var date = new Date();
|
var date = new Date();
|
||||||
var time = date.getTime();
|
var time = date.getTime();
|
||||||
this.lastEventTime = time;
|
this.lastEventTime = time;
|
||||||
@ -629,9 +618,20 @@ Kinetic.Stage.prototype = {
|
|||||||
}, false);
|
}, false);
|
||||||
|
|
||||||
this.content.addEventListener('mousemove', function(evt) {
|
this.content.addEventListener('mousemove', function(evt) {
|
||||||
that.mouseUp = false;
|
/*
|
||||||
that.mouseDown = false;
|
* throttle mousemove
|
||||||
that._handleStageEvent(evt);
|
*/
|
||||||
|
var throttle = that.attrs.throttle;
|
||||||
|
var date = new Date();
|
||||||
|
var time = date.getTime();
|
||||||
|
var timeDiff = time - that.lastEventTime;
|
||||||
|
var tt = 1000 / throttle;
|
||||||
|
|
||||||
|
if(timeDiff >= tt) {
|
||||||
|
that.mouseUp = false;
|
||||||
|
that.mouseDown = false;
|
||||||
|
that._handleStageEvent(evt);
|
||||||
|
}
|
||||||
}, false);
|
}, false);
|
||||||
|
|
||||||
this.content.addEventListener('mouseup', function(evt) {
|
this.content.addEventListener('mouseup', function(evt) {
|
||||||
@ -640,11 +640,10 @@ Kinetic.Stage.prototype = {
|
|||||||
that._handleStageEvent(evt);
|
that._handleStageEvent(evt);
|
||||||
that.clickStart = false;
|
that.clickStart = false;
|
||||||
}, false);
|
}, false);
|
||||||
/*
|
|
||||||
this.content.addEventListener('mouseover', function(evt) {
|
this.content.addEventListener('mouseover', function(evt) {
|
||||||
that._handleStageEvent(evt);
|
that._handleStageEvent(evt);
|
||||||
}, false);
|
}, false);
|
||||||
*/
|
|
||||||
|
|
||||||
this.content.addEventListener('mouseout', function(evt) {
|
this.content.addEventListener('mouseout', function(evt) {
|
||||||
// if there's a current target shape, run mouseout handlers
|
// if there's a current target shape, run mouseout handlers
|
||||||
@ -671,8 +670,19 @@ Kinetic.Stage.prototype = {
|
|||||||
}, false);
|
}, false);
|
||||||
|
|
||||||
this.content.addEventListener('touchmove', function(evt) {
|
this.content.addEventListener('touchmove', function(evt) {
|
||||||
evt.preventDefault();
|
/*
|
||||||
that._handleStageEvent(evt);
|
* throttle touchmove
|
||||||
|
*/
|
||||||
|
var throttle = that.attrs.throttle;
|
||||||
|
var date = new Date();
|
||||||
|
var time = date.getTime();
|
||||||
|
var timeDiff = time - that.lastEventTime;
|
||||||
|
var tt = 1000 / throttle;
|
||||||
|
|
||||||
|
if(timeDiff >= tt) {
|
||||||
|
evt.preventDefault();
|
||||||
|
that._handleStageEvent(evt);
|
||||||
|
}
|
||||||
}, false);
|
}, false);
|
||||||
|
|
||||||
this.content.addEventListener('touchend', function(evt) {
|
this.content.addEventListener('touchend', function(evt) {
|
||||||
|
Loading…
Reference in New Issue
Block a user