Skip to content

Instantly share code, notes, and snippets.

@dylanvalade
dylanvalade / jquery.lazy.ajax.js
Last active April 23, 2022 03:50
Ajax jQuery Lazy Image Load
/*
For jQuery.lazy https://github.com/eisbehr-/jquery.lazy
You MUST have a src value on the img for lazy loading to run even if the preloader.gif doesn't exist
Do not leave that src attribute blank:
<img class="load" data-src="path_to/lazy-loaded-image.jpg" src="path_to/preloader.gif" />
In my ajax callback:
loadImages('img.load');
@dylanvalade
dylanvalade / bootstrap-3-dropdown-on-hover.css
Last active September 20, 2017 00:26
Bootstrap 3 Dropdown Menus On Hover
/* Enable Bootstrap Hover Drop Downs */
.dropdown-menu li:hover .sub-menu {
visibility: visible;
}
.dropdown:hover .dropdown-menu {
display: block;
}
@dylanvalade
dylanvalade / bootstrap-3-carousel-keyboard.js
Last active June 22, 2017 20:42
Bootstrap carousel keyboard event controls for next and previous slides.
@dylanvalade
dylanvalade / jquery-center-vertical.js
Last active September 20, 2016 14:07
Center child element vertically within parent with jQuery
// child: jquery object e.g $(".active .slide-caption")
// parent: jquery object e.g $(".active.slide")
// property (string): CSS property to change depending on your CSS positioning e.g. "top", "margin-top" or "bottom"
function centerVertical(child, parent, property) {
var parentHeight = parent.height(),
childHeight = child.height();
// Handle edge cases with padding or margins affecting child.height() calculation
if (child.find("h1").length) {
@dylanvalade
dylanvalade / jquery-responsive-iframes.js
Last active April 7, 2016 01:52
jQuery Responsive iFrames
// Make all iframes responsive
// Handle video embeds with aspect ratio
// Input: void
// Return: void
// Dependencies: jQuery
// Call responsiveIframes() in $( document ).ready() or $( window ).load after any DOM manipulation
function responsiveIframes () {
// Handle iframes
if( $('iframe').length ) {
@dylanvalade
dylanvalade / google-analytics-cross-domain-tracking-linker-plugin.html
Last active March 10, 2016 22:07
Google Analytics Cross Domain Tracking with Linker Plugin
<!-- Cross Domain Analytics Provided by Google Support -->
<!--
1. Log into Analytics and go to Admin > (Property Column) Tracking Info > Referral Exclusion List
2. Add each linked domain to the list, which says that these are not referrals - they are continutations of the same visit
-->
<!-- Primary Domain Tracking Script (e.g. hayowentha.org) -->
<script>
(function(i,s,o,g,r,a,m){i['GoogleAnalyticsObject']=r;i[r]=i[r]||function(){
@dylanvalade
dylanvalade / causedrop-basic-install-example.html
Last active February 26, 2016 15:07
Causedrop Basic Install Example
<script>
// Use isogram attribute naming convention from Google
(function(i,s,o,g,r,a,m){
i['causedropObject']=r;
i[r]=i[r] || function(){
(i[r].q=i[r].q||[]).push(arguments)},
i[r].l=1*new Date();a=s.createElement(o),
m=s.getElementsByTagName(o)[0];
a.async=1;
@dylanvalade
dylanvalade / causedrop-paste-ad-scripts-example.html
Last active February 26, 2016 15:02
Causedrop Step 1: Add your cause's ad scripts. Fictional example for World Wide Fund for Nature (WWF)
<!-- WWF's Facebook Code for Ad Audience Targeting -->
<script type="text/javascript">
var fb_param = {};
fb_param.pixel_id = '60063372118';
fb_param.value = '0.00';
(function(){
var fpw = document.createElement('script');
fpw.async = true;
fpw.src = '//connect.facebook.net/en_US/fp.js';
var ref = document.getElementsByTagName('script')[0];
@dylanvalade
dylanvalade / bootstrap-3-xs-offset-shim.css
Created November 7, 2013 22:11
Add col-xs-offset-* shim to Bootstrap 3 for the mobile (xs) display responsive column offsetting that does not exist in the standard Bootstrap CSS.
/*
Include this after bootstrap.css
Add a class of 'col-xs-offset-*' and
if you want to disable the offset at a larger size add in 'col-*-offset-0'
Examples:
All display sizes (xs,sm,md,lg) have an offset of 1
<div class="col-xs-11 col-xs-offset-1 col-sm-3">