From 700a90d4dd6c75286a746f61a1ea3445b3fbca0c Mon Sep 17 00:00:00 2001 From: gyachuk Date: Tue, 10 Nov 2015 13:19:39 -0800 Subject: [PATCH] Avoid multiple initializations Calling $(elem).scrollToFixed() multiple times on the same elem will cause listeners to be attached on each call. This avoids the multiple listeners, with the downside of being unable to reset options. --- .gitignore | 2 ++ jquery-scrolltofixed.js | 2 +- 2 files changed, 3 insertions(+), 1 deletion(-) create mode 100644 .gitignore diff --git a/.gitignore b/.gitignore new file mode 100644 index 0000000..e14257e --- /dev/null +++ b/.gitignore @@ -0,0 +1,2 @@ +.idea/* +*.iml diff --git a/jquery-scrolltofixed.js b/jquery-scrolltofixed.js index aee7fa0..a7ff1ba 100644 --- a/jquery-scrolltofixed.js +++ b/jquery-scrolltofixed.js @@ -561,7 +561,7 @@ // page is scrolled. $.fn.scrollToFixed = function(options) { return this.each(function() { - (new $.ScrollToFixed(this, options)); + ($.isScrollToFixed(this) ? this : new $.ScrollToFixed(this, options)); }); }; })(jQuery);