Skip to content

Commit 7d52f57

Browse files
committed
Merge pull request webpop#18 from wolever/gh-pages
Add 'padding' option
2 parents 7eb3d74 + 5567616 commit 7d52f57

File tree

3 files changed

+19
-6
lines changed

3 files changed

+19
-6
lines changed

README.md

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,10 @@ To make a pinned element stay within an outer container, use the containerSelect
1414

1515
$(".pinned").pin({containerSelector: ".container"})
1616

17+
Padding can also be added around the pinned element while scrolling:
18+
19+
$(".pinned").pin({padding: {top: 10, bottom: 10}})
20+
1721
That's it - go pin all the things!
1822

1923
## Examples
@@ -29,4 +33,4 @@ Redistribution and use in source and binary forms, with or without modification,
2933

3034
Redistributions of source code must retain the above copyright notice, this list of conditions and the following disclaimer.
3135
Redistributions in binary form must reproduce the above copyright notice, this list of conditions and the following disclaimer in the documentation and/or other materials provided with the distribution.
32-
THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
36+
THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.

jquery.pin.js

Lines changed: 10 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -28,9 +28,15 @@
2828
$this.wrap("<div class='pin-wrapper'>");
2929
}
3030

31+
var pad = $.extend({
32+
top: 0,
33+
bottom: 0
34+
}, options.padding || {});
35+
3136
$this.data("pin", {
32-
from: options.containerSelector ? containerOffset.top : offset.top,
33-
to: containerOffset.top + $container.height() - $this.outerHeight(),
37+
pad: pad,
38+
from: (options.containerSelector ? containerOffset.top : offset.top) - pad.top,
39+
to: containerOffset.top + $container.height() - $this.outerHeight() - pad.bottom,
3440
end: containerOffset.top + $container.height(),
3541
parentTop: parentOffset.top
3642
});
@@ -67,13 +73,13 @@
6773
if (from < scrollY && to > scrollY) {
6874
!($this.css("position") == "fixed") && $this.css({
6975
left: $this.offset().left,
70-
top: 0
76+
top: data.pad.top
7177
}).css("position", "fixed");
7278
if (options.activeClass) { $this.addClass(options.activeClass); }
7379
} else if (scrollY >= to) {
7480
$this.css({
7581
left: "",
76-
top: to - data.parentTop
82+
top: to - data.parentTop + data.pad.top
7783
}).css("position", "absolute");
7884
if (options.activeClass) { $this.addClass(options.activeClass); }
7985
} else {

jquery.pin.min.js

Lines changed: 4 additions & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

0 commit comments

Comments
 (0)