Skip to content

Instantly share code, notes, and snippets.

View lizardking8610's full-sized avatar

Robert lizardking8610

View GitHub Profile
@lizardking8610
lizardking8610 / .htaccess
Created May 18, 2017 17:23
HTAccess: 301 redirect
Redirect 301 /oldpage.html http://www.yoursite.com/newpage.html
Redirect 301 /oldpage2.html http://www.yoursite.com/folder/
@lizardking8610
lizardking8610 / smoothscroll.js
Created May 18, 2017 17:14
jQuery: smooth scrolling
// Scroll to specific values
// scrollTo is the same
window.scroll({
top: 2500,
left: 0,
behavior: 'smooth'
});
// Scroll certain amounts from current position
window.scrollBy({
@lizardking8610
lizardking8610 / triggerclick.js
Created May 18, 2017 17:12
jQuery: click trigger on input when label clicked
var labelID;
$('label').click(function() {
labelID = $(this).attr('for');
$('#'+labelID).trigger('click');
});
//All browsers except IE will do this when you code it this way below:
@lizardking8610
lizardking8610 / notpresentLoad.js
Created May 18, 2017 17:09
jQuery: if not present then load jQuery
//using async loading
// Only do anything if jQuery isn't defined
if (typeof jQuery == 'undefined') {
if (typeof $ == 'function') {
// warning, global var
thisPageUsingOtherJSLibrary = true;
}
function getScript(url, success) {
@lizardking8610
lizardking8610 / konami.js
Created May 18, 2017 17:07
jQuery: Konami code easter egg
var kkeys = [], konami = "38,38,40,40,37,39,37,39,66,65";
$(document).keydown(function(e) {
kkeys.push( e.keyCode );
if ( kkeys.toString().indexOf( konami ) >= 0 ) {
$(document).unbind('keydown',arguments.callee);
@lizardking8610
lizardking8610 / stickyfooter.css
Created May 18, 2017 17:05
jQuery: sticky footer
#footer { height: 100px; }
@lizardking8610
lizardking8610 / linkshighlight.js
Created May 18, 2017 17:04
jQuery: highlight links to current page
$(function(){
$("a").each(function(){
if ($(this).attr("href") == window.location.pathname){
$(this).addClass("selected");
}
});
});
@lizardking8610
lizardking8610 / imagefademenu.css
Created May 18, 2017 17:03
jQuery: image fade on nav into another image
ul#menu li a{float:left;display:block;background:url("images/menu.png") no-repeat;width:150px;text-indent:-9999px;height:50px}
ul#menu li#home a{background-position:0px 0px}
ul#menu li#about a{background-position:-150px 0px}
ul#menu li#services a{background-position:-300px 0px}
ul#menu li#contact a{background-position:-450px 0px}
ul#menu li a span {background:url("images/menu.png");height:50px;display:block}
ul#menu li#home a span{background-position:0px -50px}
ul#menu li#about a span{background-position:-150px -50px}
ul#menu li#services a span{background-position:-300px -50px}
@lizardking8610
lizardking8610 / loading.html
Created May 18, 2017 17:00
jQuery: display loading graphic while page renders
<!DOCTYPE html>
<html class="no-js">
<head>
<meta charset='UTF-8'>
<title>Simple Loader</title>
<style>
/* This only works with JavaScript,
@lizardking8610
lizardking8610 / doesexist.js
Last active May 18, 2017 16:59
jQuery: does element exists
if ( $('#myElement').length ) {
// it exists
}
//>0 was not required
//if ($('#myElement').length > 0) {
// it exists
}//