Skip to content

Instantly share code, notes, and snippets.

View MikeMcChillin's full-sized avatar

Michael McMillan MikeMcChillin

View GitHub Profile
@MikeMcChillin
MikeMcChillin / arrow-keys.coffee
Created April 9, 2013 04:27
Arrow Key Functions
document.onkeydown = (event)->
left = 37
up = 38
right = 39
down = 40
switch event.keyCode
when left then
when right then
when up then
when down then
@MikeMcChillin
MikeMcChillin / widows.coffee
Created April 8, 2013 17:17
Prevents widows in headlines.
#######################################
## Prevent widows on headlines!
#######################################
widowSelector = $('header h2')
widowSelector.each ->
wordArray = $(this).text().split(" ")
finalTitle = ""
i = 0
while i <= wordArray.length - 1
// --------------------------------------------------------
// arrows
// --------------------------------------------------------
// $direction: top, left, right, bottom, top-left, top-right, bottom-left, bottom-right
// $color: hex, rgb or rbga
// $size: px or em
// @example
// .element{
// @include arrow(top, #000, 50px);
// }
@MikeMcChillin
MikeMcChillin / font-face.sass
Created April 8, 2013 03:16
Font-face compass
@import compass/css3/font-face
$font-name: "myfont"
+font-face("#{$font-name}", font-files( "#{$font-name}.woff", "#{$font-name}.ttf", "#{$font-name}.svg"), "#{$font-name}.eot", 300, normal)
@mixin myfont
font-family: 'myfont', arial, sans-serif
font-weight: normal
// Usage
h1
@MikeMcChillin
MikeMcChillin / px-to-ems.sass
Created April 8, 2013 02:43
Converts px to ems.
// Converts px to ems
// http://www.pjmccormick.com/sweet-sass-function-convert-px-em
@function em($target, $context: $base-font-size)
@if $target == 0
@return 0
@return $target / $context + 0em
$base-font-size: 16px
#######################
# Email subscribe
#######################
form = $("#subscribe")
form.submit (e) ->
e.preventDefault()
form.removeClass('shake')
$.getJSON @action + "?callback=?", $(this).serialize(), (data) ->
messageNode = $('.message')
@MikeMcChillin
MikeMcChillin / debouncedScrollEvents.js
Last active December 15, 2015 22:29
Set up scroll events. There's also this: http://codepen.io/MikeMcChillin/pen/lDcwq which uses Ben Alman's jquery throttle.
/**
* scrollEvents.js
*
* Licensed under the MIT license.
* http://www.opensource.org/licenses/mit-license.php
*
*/
// http://tympanus.net/codrops/2013/06/06/on-scroll-animated-header/
var scrollEvents = (function() {
@MikeMcChillin
MikeMcChillin / scrollio.coffee
Last active December 15, 2015 22:29
Scrollio smooth scrolls to a target, with speed & easing. Perfect for in-page navigation.
#######################
# Smooth scroll
#######################
scrollio = (target, speed) ->
$("html, body").animate
scrollTop: $(target).offset().top
, speed, "easeInOutExpo"
## Set up an event trigger for scrollio