Skip to content

Instantly share code, notes, and snippets.

@elisechant
Last active August 29, 2015 14:19
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save elisechant/9e572954abcd90b7f1f4 to your computer and use it in GitHub Desktop.
Save elisechant/9e572954abcd90b7f1f4 to your computer and use it in GitHub Desktop.
Element resize events
var Resizable = (function(window, $) {
'use strict';
function Resizable(el, options) {
this.el = el;
this.$el = $(el);
this.init();
return this;
}
Resizable.prototype.init = function() {
this.bind();
};
Resizable.prototype.bind = function() {
var mousePos = {};
// bind to the body as the 'mouseup' event might be sent to a
// different HTML element than the 'mousemove' event was
$(window).on('mouseup.resizable', function(e) {
$(window).off('mousemove.resizable');
console.log('mouseup', mousePos);
});
this.$el.on('mousedown.resizable', function(e) {
mousePos = {
x: e.pageX,
y: e.pageY
};
console.log('mousedown', mousePos);
$(window).on('mousemove.resizable', function(e) {
mousePos = {
x: e.pageX,
y: e.pageY
};
console.log('mousemove', mousePos)
});
});
console.log('bind', mousePos)
};
return Resizable;
}(window, jQuery));
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment