Last active
August 29, 2015 14:19
-
-
Save elisechant/9e572954abcd90b7f1f4 to your computer and use it in GitHub Desktop.
Element resize events
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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