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
38
dist/kinetic-core.js
vendored
38
dist/kinetic-core.js
vendored
@ -2005,22 +2005,11 @@ Kinetic.Stage.prototype = {
|
||||
|
||||
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
|
||||
* @param {Event} evt
|
||||
*/
|
||||
_handleStageEventContinue: function(evt) {
|
||||
_handleStageEvent: function(evt) {
|
||||
var date = new Date();
|
||||
var time = date.getTime();
|
||||
this.lastEventTime = time;
|
||||
@ -2083,9 +2072,20 @@ Kinetic.Stage.prototype = {
|
||||
}, false);
|
||||
|
||||
this.content.addEventListener('mousemove', function(evt) {
|
||||
/*
|
||||
* throttle mousemove
|
||||
*/
|
||||
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);
|
||||
|
||||
this.content.addEventListener('mouseup', function(evt) {
|
||||
@ -2094,11 +2094,10 @@ Kinetic.Stage.prototype = {
|
||||
that._handleStageEvent(evt);
|
||||
that.clickStart = false;
|
||||
}, false);
|
||||
/*
|
||||
|
||||
this.content.addEventListener('mouseover', function(evt) {
|
||||
that._handleStageEvent(evt);
|
||||
}, false);
|
||||
*/
|
||||
|
||||
this.content.addEventListener('mouseout', function(evt) {
|
||||
// if there's a current target shape, run mouseout handlers
|
||||
@ -2125,8 +2124,19 @@ Kinetic.Stage.prototype = {
|
||||
}, false);
|
||||
|
||||
this.content.addEventListener('touchmove', function(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);
|
||||
|
||||
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
38
src/Stage.js
38
src/Stage.js
@ -551,22 +551,11 @@ Kinetic.Stage.prototype = {
|
||||
|
||||
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
|
||||
* @param {Event} evt
|
||||
*/
|
||||
_handleStageEventContinue: function(evt) {
|
||||
_handleStageEvent: function(evt) {
|
||||
var date = new Date();
|
||||
var time = date.getTime();
|
||||
this.lastEventTime = time;
|
||||
@ -629,9 +618,20 @@ Kinetic.Stage.prototype = {
|
||||
}, false);
|
||||
|
||||
this.content.addEventListener('mousemove', function(evt) {
|
||||
/*
|
||||
* throttle mousemove
|
||||
*/
|
||||
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);
|
||||
|
||||
this.content.addEventListener('mouseup', function(evt) {
|
||||
@ -640,11 +640,10 @@ Kinetic.Stage.prototype = {
|
||||
that._handleStageEvent(evt);
|
||||
that.clickStart = false;
|
||||
}, false);
|
||||
/*
|
||||
|
||||
this.content.addEventListener('mouseover', function(evt) {
|
||||
that._handleStageEvent(evt);
|
||||
}, false);
|
||||
*/
|
||||
|
||||
this.content.addEventListener('mouseout', function(evt) {
|
||||
// if there's a current target shape, run mouseout handlers
|
||||
@ -671,8 +670,19 @@ Kinetic.Stage.prototype = {
|
||||
}, false);
|
||||
|
||||
this.content.addEventListener('touchmove', function(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);
|
||||
|
||||
this.content.addEventListener('touchend', function(evt) {
|
||||
|
Loading…
Reference in New Issue
Block a user