Add smooth scroll and sticky scripts

This commit is contained in:
Michael Rose 2016-03-10 13:06:17 -05:00
parent caefcce729
commit 3df0afbdc9
5 changed files with 54 additions and 19 deletions

View file

@ -2,33 +2,51 @@
jQuery plugin settings and other scripts jQuery plugin settings and other scripts
========================================================================== */ ========================================================================== */
/* fitvids.js */ $(document).ready(function(){
$(function() { // FitVids init
$("article").fitVids(); $("#main").fitVids();
});
// init sticky sidebar
$(".sticky").Stickyfill();
// init smooth scroll
$("a").smoothScroll({offset: -20});
/* add lightbox class to all image links */ // add lightbox class to all image links
$("a[href$='.jpg'],a[href$='.jpeg'],a[href$='.JPG'],a[href$='.png'],a[href$='.gif']").addClass("image-popup");
$("a[href$='.jpg'],a[href$='.jpeg'],a[href$='.JPG'],a[href$='.png'],a[href$='.gif']").addClass("image-popup"); // Magnific-Popup options
/* Magnific-Popup options */
$(document).ready(function() {
$(".image-popup").magnificPopup({ $(".image-popup").magnificPopup({
type: "image", disableOn: function() {
tLoading: "Loading image #%curr%...", if( $(window).width() < 500 ) {
return false;
}
return true;
},
type: 'image',
tLoading: 'Loading image #%curr%...',
gallery: { gallery: {
enabled: true, enabled: true,
navigateByImgClick: true, navigateByImgClick: true,
preload: [0,1] // will preload 0 - before current, and 1 after the current image preload: [0,1] // Will preload 0 - before current, and 1 after the current image
}, },
image: { image: {
tError: "<a href='%url%'>Image #%curr%</a> could not be loaded.", tError: '<a href="%url%">Image #%curr%</a> could not be loaded.',
}, },
removalDelay: 300, // delay in milliseconds before popup is removed removalDelay: 500, // Delay in milliseconds before popup is removed
mainClass: "mfp-fade" // Class that is added to body when popup is open.
// make it unique to apply your CSS animations just to this exact popup
mainClass: 'mfp-zoom-in',
callbacks: {
beforeOpen: function() {
// just a hack that adds mfp-anim class to markup
this.st.image.markup = this.st.image.markup.replace('mfp-figure', 'mfp-figure mfp-with-anim');
}
},
closeOnContentClick: true,
midClick: true // allow opening popup on middle mouse click. Always set it to true if you don't provide alternative source.
}); });
}); });

View file

@ -0,0 +1,8 @@
/*!
* jQuery Smooth Scroll - v1.7.2 - 2016-01-23
* https://github.com/kswedberg/jquery-smooth-scroll
* Copyright (c) 2016 Karl Swedberg
* Licensed MIT
*/
!function(a){"function"==typeof define&&define.amd?define(["jquery"],a):a("object"==typeof module&&module.exports?require("jquery"):jQuery)}(function(a){var b="1.7.2",c={},d={exclude:[],excludeWithin:[],offset:0,direction:"top",delegateSelector:null,scrollElement:null,scrollTarget:null,beforeScroll:function(){},afterScroll:function(){},easing:"swing",speed:400,autoCoefficient:2,preventDefault:!0},e=function(b){var c=[],d=!1,e=b.dir&&"left"===b.dir?"scrollLeft":"scrollTop";return this.each(function(){var b=a(this);if(this!==document&&this!==window)return!document.scrollingElement||this!==document.documentElement&&this!==document.body?void(b[e]()>0?c.push(this):(b[e](1),d=b[e]()>0,d&&c.push(this),b[e](0))):(c.push(document.scrollingElement),!1)}),c.length||this.each(function(){this===document.documentElement&&"smooth"===a(this).css("scrollBehavior")&&(c=[this]),c.length||"BODY"!==this.nodeName||(c=[this])}),"first"===b.el&&c.length>1&&(c=[c[0]]),c};a.fn.extend({scrollable:function(a){var b=e.call(this,{dir:a});return this.pushStack(b)},firstScrollable:function(a){var b=e.call(this,{el:"first",dir:a});return this.pushStack(b)},smoothScroll:function(b,c){if(b=b||{},"options"===b)return c?this.each(function(){var b=a(this),d=a.extend(b.data("ssOpts")||{},c);a(this).data("ssOpts",d)}):this.first().data("ssOpts");var d=a.extend({},a.fn.smoothScroll.defaults,b),e=function(b){var c=function(a){return a.replace(/(:|\.|\/)/g,"\\$1")},e=this,f=a(this),g=a.extend({},d,f.data("ssOpts")||{}),h=d.exclude,i=g.excludeWithin,j=0,k=0,l=!0,m={},n=a.smoothScroll.filterPath(location.pathname),o=a.smoothScroll.filterPath(e.pathname),p=location.hostname===e.hostname||!e.hostname,q=g.scrollTarget||o===n,r=c(e.hash);if(r&&!a(r).length&&(l=!1),g.scrollTarget||p&&q&&r){for(;l&&j<h.length;)f.is(c(h[j++]))&&(l=!1);for(;l&&k<i.length;)f.closest(i[k++]).length&&(l=!1)}else l=!1;l&&(g.preventDefault&&b.preventDefault(),a.extend(m,g,{scrollTarget:g.scrollTarget||r,link:e}),a.smoothScroll(m))};return null!==b.delegateSelector?this.undelegate(b.delegateSelector,"click.smoothscroll").delegate(b.delegateSelector,"click.smoothscroll",e):this.unbind("click.smoothscroll").bind("click.smoothscroll",e),this}}),a.smoothScroll=function(b,d){if("options"===b&&"object"==typeof d)return a.extend(c,d);var e,f,g,h,i,j=0,k="offset",l="scrollTop",m={},n={};"number"==typeof b?(e=a.extend({link:null},a.fn.smoothScroll.defaults,c),g=b):(e=a.extend({link:null},a.fn.smoothScroll.defaults,b||{},c),e.scrollElement&&(k="position","static"===e.scrollElement.css("position")&&e.scrollElement.css("position","relative"))),l="left"===e.direction?"scrollLeft":l,e.scrollElement?(f=e.scrollElement,/^(?:HTML|BODY)$/.test(f[0].nodeName)||(j=f[l]())):f=a("html, body").firstScrollable(e.direction),e.beforeScroll.call(f,e),g="number"==typeof b?b:d||a(e.scrollTarget)[k]()&&a(e.scrollTarget)[k]()[e.direction]||0,m[l]=g+j+e.offset,h=e.speed,"auto"===h&&(i=Math.abs(m[l]-f[l]()),h=i/e.autoCoefficient),n={duration:h,easing:e.easing,complete:function(){e.afterScroll.call(e.link,e)}},e.step&&(n.step=e.step),f.length?f.stop().animate(m,n):e.afterScroll.call(e.link,e)},a.smoothScroll.version=b,a.smoothScroll.filterPath=function(a){return a=a||"",a.replace(/^\//,"").replace(/(?:index|default).[a-zA-Z]{3,4}$/,"").replace(/\/$/,"")},a.fn.smoothScroll.defaults=d});

8
_assets/js/plugins/stickyfill.min.js vendored Normal file

File diff suppressed because one or more lines are too long

View file

@ -35,7 +35,7 @@ layout: compress
{% endif %} {% endif %}
<div id="main" role="main"> <div id="main" role="main">
<div class="sidebar"> <div class="sidebar sticky">
{% if page.author_profile %}{% include author-profile %}{% endif %} {% if page.author_profile %}{% include author-profile %}{% endif %}
{% if page.sidebar %} {% if page.sidebar %}
{% for s in page.sidebar %} {% for s in page.sidebar %}

File diff suppressed because one or more lines are too long