diff --git a/index.js b/index.js index 63c6f11..0196ed3 100644 --- a/index.js +++ b/index.js @@ -59,7 +59,6 @@ function Tip(content, options) { this.delay = options.delay || 300; this.el = html.cloneNode(true); this.events = events(this.el, this); - this.winEvents = events(window, this); this.classes = classes(this.el); this.inner = query('.tip-inner', this.el); this.message(content); @@ -220,8 +219,11 @@ Tip.prototype.show = function(el){ this.reposition(); this.emit('show', this.target); - this.winEvents.bind('resize', 'reposition'); - this.winEvents.bind('scroll', 'reposition'); + if (!this.winEvents) { + this.winEvents = events(window, this); + this.winEvents.bind('resize', 'reposition'); + this.winEvents.bind('scroll', 'reposition'); + } return this; }; @@ -404,8 +406,10 @@ Tip.prototype.hide = function(ms){ */ Tip.prototype.remove = function(){ - this.winEvents.unbind('resize', 'reposition'); - this.winEvents.unbind('scroll', 'reposition'); + if (this.winEvents) { + this.winEvents.unbind(); + this.winEvents = null; + } this.emit('hide'); var parent = this.el.parentNode; diff --git a/test/index.html b/test/index.html index 1b00156..d9e6330 100644 --- a/test/index.html +++ b/test/index.html @@ -42,11 +42,17 @@ #border { border-width: 10px; } + .hide-tip { + margin-left: 4em; + } Tip +
+ +