Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Option to stack bottom #4

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,8 @@ _Slinky is currently implemented as a jQuery plugin but if there is enough deman

Download the [production version][min] or the [development version][max] and include it after jQuery. Then just call `$('.nav').slinky()` for example to enable Slinky on all elements with a `nav` class.

If you want the headers to stack only on the top but not the bottom, you can pass in an option during the initialization. `$('.nav').slinky({ stackBottom: false })`

[min]: https://raw.github.com/iclanzan/slinky/master/dist/jquery.slinky.min.js
[max]: https://raw.github.com/iclanzan/slinky/master/dist/jquery.slinky.js

Expand Down Expand Up @@ -57,5 +59,6 @@ Thanks to [@callmevlad](https://twitter.com/callmevlad) for the idea!

## Release History ##

+ **v0.1.2 (2014-09-23)** Added option for not stacking headers on the bottom.
+ **v0.1.1 (2014-02-06)** Fixed rendering glitches on high density screens.
+ **v0.1.0 (2014-01-31)** Initial version
6 changes: 4 additions & 2 deletions dist/jquery.slinky.js
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,9 @@
var pluginName = 'slinky';

var slinky = $.fn[pluginName] = function (options) {
options = $.extend({}, slinky.options, options);
options = $.extend({
stackBottom: true
}, slinky.options, options);

return this.each(function () {
var $element = $(this);
Expand All @@ -33,7 +35,7 @@
if (top <= header.top) {
position = 'top';
}
else if (top + header.height >= scrollerHeight - header.bottom) {
else if (options.stackBottom === true && top + header.height >= scrollerHeight - header.bottom) {
position = 'bottom';
}

Expand Down
2 changes: 1 addition & 1 deletion dist/jquery.slinky.min.js

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

6 changes: 4 additions & 2 deletions src/slinky.js
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,9 @@
var pluginName = 'slinky';

var slinky = $.fn[pluginName] = function (options) {
options = $.extend({}, slinky.options, options);
options = $.extend({
stackBottom: true
}, slinky.options, options);

return this.each(function () {
var $element = $(this);
Expand All @@ -33,7 +35,7 @@
if (top <= header.top) {
position = 'top';
}
else if (top + header.height >= scrollerHeight - header.bottom) {
else if (options.stackBottom === true && top + header.height >= scrollerHeight - header.bottom) {
position = 'bottom';
}

Expand Down
2 changes: 1 addition & 1 deletion test/slinky.html
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
<meta charset="utf-8">
<title>Slinky Test Suite</title>
<!-- Load local jQuery. -->
<script src="../bower_components/jquery/jquery.js"></script>
<script src="../bower_components/jquery/dist/jquery.js"></script>
<!-- Load local QUnit. -->
<link rel="stylesheet" href="../bower_components/qunit/qunit/qunit.css" media="screen">
<script src="../bower_components/qunit/qunit/qunit.js"></script>
Expand Down
26 changes: 26 additions & 0 deletions test/slinky_test.js
Original file line number Diff line number Diff line change
Expand Up @@ -69,6 +69,32 @@
strictEqual($headers.eq(6).css('bottom'), '0px', 'last header should be positioned');
});

test('initial header positions with no bottom stack', function() {
var $headers = $('header');
this.$nav.slinky({stackBottom:false});

expect(13);
strictEqual($headers.eq(0).css('position'), 'absolute', 'first header should be positioned');
strictEqual($headers.eq(0).css('top'), '0px', 'first header should be positioned');

strictEqual($headers.eq(1).css('position'), 'static', 'second header should be static');

strictEqual($headers.eq(2).css('position'), 'static', 'third header should be positioned');
strictEqual($headers.eq(2).css('bottom'), 'auto', 'third header should be positioned');

strictEqual($headers.eq(3).css('position'), 'static', 'fourth header should be positioned');
strictEqual($headers.eq(3).css('bottom'), 'auto', 'fourth header should be positioned');

strictEqual($headers.eq(4).css('position'), 'static', 'fifth header should be positioned');
strictEqual($headers.eq(4).css('bottom'), 'auto', 'fifth header should be positioned');

strictEqual($headers.eq(5).css('position'), 'static', 'sixth header should be positioned');
strictEqual($headers.eq(5).css('bottom'), 'auto', 'sixth header should be positioned');

strictEqual($headers.eq(6).css('position'), 'static', 'last header should be positioned');
strictEqual($headers.eq(6).css('bottom'), 'auto', 'last header should be positioned');
});

asyncTest('half-way scroll header positions', function() {
var $headers = $('header');
this.$nav.slinky();
Expand Down