52 lines
1.4 KiB
JavaScript
52 lines
1.4 KiB
JavaScript
|
var cj = cj ? cj : {};
|
||
|
(function($) {
|
||
|
$.extend(cj, {
|
||
|
scrollTo: {
|
||
|
// jQuery DOM caching
|
||
|
$scrollTo: null,
|
||
|
// CSS selectors
|
||
|
scrollToSelector: '[data-scroll-to-id]',
|
||
|
// Classes
|
||
|
// Misc
|
||
|
speed: 500,
|
||
|
|
||
|
init: function() {
|
||
|
var self = this;
|
||
|
|
||
|
self.$scrollTo = $(self.scrollToSelector);
|
||
|
|
||
|
if (!self.$scrollTo || !self.$scrollTo.length) {
|
||
|
return;
|
||
|
}
|
||
|
|
||
|
self.bindEvents();
|
||
|
},
|
||
|
bindEvents: function() {
|
||
|
var self = this;
|
||
|
|
||
|
self.$scrollTo.on('click', function(e){
|
||
|
e.preventDefault();
|
||
|
|
||
|
self.scrollToId($(this));
|
||
|
});
|
||
|
},
|
||
|
scrollToId: function($trigger) {
|
||
|
var self = this,
|
||
|
id = $trigger.attr('href'),
|
||
|
offset = $trigger.attr('data-scroll-offset') || 0,
|
||
|
speed = $trigger.attr('data-scroll-speed') || self.speed;
|
||
|
|
||
|
// if (history.pushState && window.location.hash !== id) {
|
||
|
// history.pushState(null, null, id);
|
||
|
// }
|
||
|
|
||
|
cj.settings.$htmlbody.animate({
|
||
|
scrollTop: ($(id).offset().top - offset)
|
||
|
}, speed);
|
||
|
}
|
||
|
}
|
||
|
});
|
||
|
$.subscribe('pageReady', function() {
|
||
|
cj.scrollTo.init();
|
||
|
});
|
||
|
}(jQuery));
|