Skip to content

Commit

Permalink
fix bug: cannot remove wheel event
Browse files Browse the repository at this point in the history
  • Loading branch information
PengJiyuan committed Apr 28, 2018
1 parent a3c8f92 commit ed06ae3
Show file tree
Hide file tree
Showing 5 changed files with 50 additions and 17 deletions.
25 changes: 13 additions & 12 deletions dist/omg.js
Original file line number Diff line number Diff line change
Expand Up @@ -301,8 +301,19 @@ var createClass = function () {

var Event = function () {
function Event(_this) {
var _this2 = this;

classCallCheck(this, Event);

this.mouseWheel = function (e) {
if (e.deltaY && e.deltaY > 0) {
_this2._.scale = _this2._.scale - 0.01 >= _this2._.minDeviceScale ? _this2._.scale - 0.01 : _this2._.minDeviceScale;
} else if (e.deltaY && e.deltaY < 0) {
_this2._.scale = _this2._.scale + 0.01 <= _this2._.maxDeviceScale ? _this2._.scale + 0.01 : _this2._.maxDeviceScale;
}
_this2._.redraw();
};

// global this
this._ = _this;
this.triggeredMouseDown = false;
Expand Down Expand Up @@ -357,22 +368,12 @@ var Event = function () {
}, {
key: 'bindMouseWheel',
value: function bindMouseWheel() {
bind(this._.element, 'wheel', this.mouseWheel.bind(this));
bind(this._.element, 'wheel', this.mouseWheel);
}
}, {
key: 'unBindMouseWheel',
value: function unBindMouseWheel() {
unbind(this._.element, 'wheel', this.mouseWheel.bind(this));
}
}, {
key: 'mouseWheel',
value: function mouseWheel(e) {
if (e.deltaY && e.deltaY > 0) {
this._.scale = this._.scale - 0.01 >= this._.minDeviceScale ? this._.scale - 0.01 : this._.minDeviceScale;
} else if (e.deltaY && e.deltaY < 0) {
this._.scale = this._.scale + 0.01 <= this._.maxDeviceScale ? this._.scale + 0.01 : this._.maxDeviceScale;
}
this._.redraw();
unbind(this._.element, 'wheel', this.mouseWheel);
}
}, {
key: 'bindMouseMove',
Expand Down
2 changes: 1 addition & 1 deletion dist/omg.min.js

Large diffs are not rendered by default.

32 changes: 32 additions & 0 deletions examples/matrix.html
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,12 @@
<div class="container">
<canvas id="canvas"></canvas>
</div>
<button id="translateReverseBtn" type="button" onclick="translateReverse()" class="btn btn-info btn-rounded">
关闭拖拽
</button>
<button id="scaleeReverseBtn" type="button" onclick="scaleeReverse()" class="btn btn-info btn-rounded">
关闭缩放
</button>
<script src="./omg.min.js"></script>
<script>
var stage = omg({
Expand Down Expand Up @@ -84,6 +90,32 @@

stage.show();

// 全局拖拽设置
function translateReverse() {
let translateBtn = document.getElementById("translateReverseBtn");
if (stage.enableGlobalTranslate) {
translateBtn.innerHTML = "开启拖拽";
stage.enableGlobalTranslate = false;
} else {
translateBtn.innerHTML = "关闭拖拽";
stage.enableGlobalTranslate = true;
}
stage._event.triggerEvents();
}

// 缩放设置
function scaleeReverse() {
let scaleeBtn = document.getElementById("scaleeReverseBtn");
if (stage.enableGlobalScale) {
scaleeBtn.innerHTML = "开启缩放";
stage.enableGlobalScale = false;
} else {
scaleeBtn.innerHTML = "关闭缩放";
stage.enableGlobalScale = true;
}
stage._event.triggerEvents();
}

</script>
</body>
</html>
2 changes: 1 addition & 1 deletion examples/omg.min.js

Large diffs are not rendered by default.

6 changes: 3 additions & 3 deletions src/event.js
Original file line number Diff line number Diff line change
Expand Up @@ -66,14 +66,14 @@ export class Event {
}

bindMouseWheel() {
utils.bind(this._.element, 'wheel', this.mouseWheel.bind(this));
utils.bind(this._.element, 'wheel', this.mouseWheel);
}

unBindMouseWheel() {
utils.unbind(this._.element, 'wheel', this.mouseWheel.bind(this));
utils.unbind(this._.element, 'wheel', this.mouseWheel);
}

mouseWheel(e: WheelEvent) {
mouseWheel = (e: WheelEvent) => {
if(e.deltaY && e.deltaY > 0) {
this._.scale = this._.scale - 0.01 >= this._.minDeviceScale ? this._.scale - 0.01 : this._.minDeviceScale;
} else if(e.deltaY && e.deltaY < 0) {
Expand Down

0 comments on commit ed06ae3

Please sign in to comment.