Skip to content

Instantly share code, notes, and snippets.

@vdecree
Last active August 29, 2015 14:23
Show Gist options
  • Save vdecree/e406797bce2599d709ab to your computer and use it in GitHub Desktop.
Save vdecree/e406797bce2599d709ab to your computer and use it in GitHub Desktop.
// Useful jQuery snippits b*tches.
/////////////////////////////////////////////////////////////////////////////////////////////////////////////
// On scroll add class — useful for sticky navigations
/////////////////////////////////////////////////////////////////////////////////////////////////////////////
&(function($) {
var $header = $('.header');
var $win = $(window);
var winH = $win.height(); // Get the window height.
$win.on("scroll", function () {
$header.toggleClass("sticky animated slideInDown", $(this).scrollTop() > winH/2 );
}).on("resize", function(){ // If the user resizes the window
winH = $(this).height(); // you'll need the new height value
});
});
/////////////////////////////////////////////////////////////////////////////////////////////////////////////
// Modernizr media query plugin. Great if you need to trigger some jQuery based on the users screen width
/////////////////////////////////////////////////////////////////////////////////////////////////////////////
if (Modernizr.mq('only all and (min-width: 980px)')) {
// your code here
}
/////////////////////////////////////////////////////////////////////////////////////////////////////////////
// Making checks against URL
/////////////////////////////////////////////////////////////////////////////////////////////////////////////
if(window.location.href.indexOf("franky") > -1) {
alert("your url contains the name franky");
}
/////////////////////////////////////////////////////////////////////////////////////////////////////////////
// On scroll make element animate up/down and fix to top of window
/////////////////////////////////////////////////////////////////////////////////////////////////////////////
$(document).ready(function() {
var offset = $('.ads').offset().top, top;
$(document).on('scroll', function() {
top = $(window).scrollTop() < offset ? '0' : $(window).scrollTop() - offset + 'px';
$('.ads').css({
'top': top
});
})
});
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment