Title and navbar fixes

This commit is contained in:
Asutosh Palai
2016-07-27 23:00:31 +05:30
parent eb980c66d8
commit 208291b786
4 changed files with 92 additions and 33 deletions

View File

@ -6,6 +6,7 @@ $(function() {
$(this).addClass(imgClass);
})
/*
var switchPos = $('#new-articles').position().top + $('#new-articles').height();
$(window).scroll(function() {
@ -17,6 +18,70 @@ $(function() {
$(".navbar-wrapper").removeClass("darken");
}
});
*/
;(function($, window, document, undefined) {
'use strict';
var elSelector = '.navbar-wrapper',
elClassHidden = 'navbar--hidden',
throttleTimeout = 250,
$element = $( elSelector );
if(!$element.length) return true;
var $window = $( window ),
wHeight = 0,
wScrollCurrent = 0,
wScrollBefore = 0,
wScrollDiff = 0,
$document = $( document ),
dHeight = 0,
throttle = function(delay, fn) {
var last, deferTimer;
return function() {
var context = this, args = arguments, now = +new Date;
if( last && now < last + delay ) {
clearTimeout( deferTimer );
deferTimer = setTimeout( function(){ last = now; fn.apply( context, args ); }, delay );
}
else {
last = now;
fn.apply( context, args );
}
};
};
$window.on( 'scroll', throttle( throttleTimeout, function() {
dHeight = $document.height();
wHeight = $window.height();
wScrollCurrent = $window.scrollTop();
wScrollDiff = wScrollBefore - wScrollCurrent;
if(wScrollCurrent <= 0) { // scrolled to the very top; element sticks to the top
$element.removeClass(elClassHidden);
$element.removeClass(elClassTop);
}
else if(wScrollDiff > 10 && $element.hasClass(elClassHidden)) // scrolled up; element slides in
$element.removeClass( elClassHidden );
else if(wScrollDiff < -10) {// scrolled down
if(wScrollCurrent + wHeight >= dHeight && $element.hasClass(elClassHidden)) // scrolled to the very bottom; element slides in
$element.removeClass( elClassHidden );
else // scrolled down; element slides out
$element.addClass( elClassHidden );
}
wScrollBefore = wScrollCurrent;
}));
})( jQuery, window, document );
});
function onYouTubeIframeAPIReady() {
@ -38,3 +103,4 @@ function onYouTubeIframeAPIReady() {
});
}