Skip to content

Instantly share code, notes, and snippets.

@ThomasLarge
Last active May 1, 2018 09:38
Show Gist options
  • Save ThomasLarge/5edcc71c9accfb038933434e0318d522 to your computer and use it in GitHub Desktop.
Save ThomasLarge/5edcc71c9accfb038933434e0318d522 to your computer and use it in GitHub Desktop.
JQuery snippets
// clickable divs
jQuery(".click-me").click(function(){
window.location=jQuery(this).find("a").attr("href");
return false;
});
// open all external links in blank
jQuery(document).ready(function() {
jQuery("a[href^=http]").each(function(){
if(this.href.indexOf(location.hostname) == -1) {
jQuery(this).attr({
target: "_blank",
});
}
})
});
// Fade out on scroll
jQuery(window).scroll(function(){
jQuery(".fadeoutup").css("opacity", 1 - jQuery(window).scrollTop() / 550);
});
// If the url has a # if else
if(window.location.hash) {
// Fragment exists
} else {
// Fragment doesn't exist
}
// This is where all of the snippets for jQuery lives
// Scrolly
jQuery(".scrolly").click(function(scroll1){
scroll1.preventDefault();
jQuery('html,body').animate({scrollTop:jQuery(this.hash).offset().top -85
}, 1000);
});
$('.waypoint-fadeInLeft').css('opacity', 0);
$('.waypoint-fadeInLeft').waypoint(function(){
$(this).addClass('fadeInLeft');
},{
offset:'90%',
triggerOnce:true
});
$('.waypoint-fadeInRight').css('opacity', 0);
$('.waypoint-fadeInRight').waypoint(function(){
$(this).addClass('fadeInRight');
},{
offset:'90%',
triggerOnce:true
});
$('.waypoint-fadeInUp').css('opacity', 0);
$('.waypoint-fadeInUp').waypoint(function(){
$(this).addClass('fadeInUp');
},{
offset:'90%',
triggerOnce:true
});
$('.waypoint-fadeIn').css('opacity', 0);
$('.waypoint-fadeIn').waypoint(function(){
$(this).addClass('fadeIn');
},{
offset:'90%',
triggerOnce:true
});\
$('.waypoint').css('opacity', 0);
$('.waypoint').waypoint(function(){
$(this).animate({opacity:1},"slow");
},{
offset:'90%',
triggerOnce:true
});
// Wrap class with a new class
jQuery( ".entry-content img" ).wrap( "<div class='img-wrap'></div>" );
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment