From 89aa497f17bd28a69ea1fd408b1648f7b7c27958 Mon Sep 17 00:00:00 2001 From: Mike Grace Date: Mon, 6 May 2013 17:38:54 -0400 Subject: [PATCH] Option to add and remove class to element being pinned as the pinning state changes. This allows CSS targeting based on if the element is being pinned or not. --- jquery.pin.js | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/jquery.pin.js b/jquery.pin.js index 180452b..d9adef4 100644 --- a/jquery.pin.js +++ b/jquery.pin.js @@ -12,6 +12,7 @@ if (options.minWidth && $window.width() <= options.minWidth) { if ($this.parent().is(".pin-wrapper")) { $this.unwrap(); } $this.css({width: "", left: "", top: "", position: ""}); + if (options.activeClass) { $this.removeClass(options.activeClass); } disabled = true; continue; } else { @@ -60,13 +61,16 @@ left: $this.offset().left, top: 0 }).css("position", "fixed"); + if (options.activeClass) { $this.addClass(options.activeClass); } } else if (scrollY >= to) { $this.css({ left: "auto", top: to - data.parentTop }).css("position", "absolute"); + if (options.activeClass) { $this.addClass(options.activeClass); } } else { $this.css({position: "", top: "", left: ""}); + if (options.activeClass) { $this.removeClass(options.activeClass); } } } };