mirror of
https://github.com/konvajs/konva.git
synced 2025-10-15 12:34:52 +08:00
applying event throttling logic to mousemove and touchmove only
This commit is contained in:
54
src/Stage.js
54
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) {
|
||||
that.mouseUp = false;
|
||||
that.mouseDown = false;
|
||||
that._handleStageEvent(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('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) {
|
||||
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);
|
||||
|
||||
this.content.addEventListener('touchend', function(evt) {
|
||||
|
Reference in New Issue
Block a user