-
Notifications
You must be signed in to change notification settings - Fork 6
/
jquery.headtacular.js
79 lines (61 loc) · 1.9 KB
/
jquery.headtacular.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
/*
**********************************************************
* Headtacular | A nice minimalist sticky header
* http://headtacular.com
*
* Version: v1.0.4
* Author: Mike Zarandona | @mikezarandona
* Release: Feb 02 2015
* Documentation update.
*
* Reqs: jQuery
*
* Usage: $('.header').headtacular();
**********************************************************
*/
(function ($, undefined) {
$.fn.headtacular = function (options) {
// Override defaults with specified options
options = $.extend({}, $.fn.headtacular.options, options);
// store the object
var elem = $(this);
// showScrollPoint option
if ( options.showScrollPoint ) {
console.log(options.scrollPoint);
$('body').append('<div id="headtacular-scroll-point" style="height: 0px; width: 100%; border-bottom: 2px solid red; position: absolute; z-index: 99999; left: 0; top: ' + options.scrollPoint + 'px;"></div>');
}
// document.scroll() event
$(document).on('ready scroll', function() {
// if scrolled past the scroll point
if ( $(document).scrollTop() > options.scrollPoint ) {
// if the object does not already have .is-stuck
if ( !elem.hasClass('is-stuck') ) {
// assign the class
elem.addClass('is-stuck');
// if parentOffset is turned on, apply the padding fix
if ( options.parentOffset ) {
elem.parent().css( 'padding-top', elem.outerHeight(true) );
}
}
}
// if not scrolled past the scroll point
else {
// if the object still has .is-stuck
if ( elem.hasClass('is-stuck') ) {
// remove the class and padding fix
elem.removeClass('is-stuck');
// if parentOffset is turned on, remove the padding fix
if ( options.parentOffset ) {
elem.parent().removeAttr('style');
}
}
}
});
};
// Default the defaults
$.fn.headtacular.options = {
scrollPoint: 10,
showScrollPoint: false,
parentOffset: true
};
})(jQuery);