Запуск события при помощи bind
Здравствуйте!
Есть код: var Book = function ($dom, $shelf) { this.$ = $dom; this.width = this.$.width(); this.x = null; this.$shelf = $shelf; this.$.data('book', this); this.init(); } Book.prototype.init = function () { this.$.mousedown(this.handlers.mousedown); this.$.mouseup(this.handlers.mouseup); } Book.prototype.handlers = { mousedown: function (e) { var book = $(this).data('book'); console.log(book); book.onMousedown(e.pageX); }, mouseup: function () { var book = $(this).data('book'); console.log(book); book.onMouseup(); }, mousemove: function (e) { var book = $(this).data('book'); console.log('Mousmove Starting!'); console.log(book); book.onMove(e.pageX); } }; Book.prototype.onMousedown = function (x) { console.log('Mouse Down!'); $(document).bind('mousemove', this.handlers.mousemove); }; Book.prototype.onMouseup = function () { console.log('Mouse Up!'); $(document).unbind('mousemove', this.handlers.mousemove); }; Book.prototype.onMove = function (x) { console.log('Mouse Move!'); } Проблема в запуске метода "onMove". mousemove запускается, но this туда не приходит. Подскажите где ошибся? сonsole.log(book); выдает undefined |
Страница находится здесь.
|
Всем спасибо, уже разобрался.:thanks:
|
Часовой пояс GMT +3, время: 23:57. |