Skip to content

Instantly share code, notes, and snippets.

@williammalo
williammalo / README.md
Last active October 6, 2015 14:18 — forked from 140bytes/LICENSE.txt
get offset of element

recursively checks every parent of the element to get the ABSOLUTE offset of the element.

call it like this:

getOff(element).x

getOff(element).y

@williammalo
williammalo / README.md
Last active October 7, 2015 01:48 — forked from 140bytes/LICENSE.txt
masonry under 140bytes

A minimalist masonry function

mason(containerElement,brickElement,brickWidth,brickHeight)

Only works with one size of brick.

The only advantage of using this over using inline-block elements is that you can use css transitions.

@williammalo
williammalo / README.md
Last active December 18, 2015 08:20 — forked from 140bytes/LICENSE.txt

##Object Merger

Recurcively merges two objects.

merge(
  {foo:"foo"},
  {bar:{lol:"lol"}}

);

@williammalo
williammalo / CircleCircleTangents.glsl
Last active December 5, 2016 17:46
Find Tangents of Two Circles in glsl, useful for calculating soft shadows https://www.shadertoy.com/view/Mtc3R2
//visual basics code from http://www.vb-helper.com/howto_net_circle_circle_tangents.html ported to glsl
vec4 FindCircleCircleIntersections(vec2 p0, float r0, vec2 p1, float r1){
vec2 dd = p1-p0;
float d = length(dd);
float a = (r0 * r0 - r1 * r1 + d * d) / (2.0 * d);
float h = sqrt(r0 * r0 - a * a);
@williammalo
williammalo / Readme.md
Created March 10, 2012 00:02 — forked from thingsinjars/LICENSE.txt
Chainable DOM Manipulation
@williammalo
williammalo / README.md
Last active January 26, 2018 21:15 — forked from 140bytes/LICENSE.txt
The cleanest, easiest dom api ever! It will change your life!

I always thought there was a better way to access the dom. This is a tool that allows you to use extremely simple syntax to access dom elements. It makes an object with the name of your choice (I chose "$") that contains a reference to all elements that have an id.

example:

<script> $.foo.innerHTML = "Hello world" </script>

You can even choose to use an object that already exists (I chose "document" because it makes sense)

@williammalo
williammalo / README.md
Last active January 27, 2018 00:48 — forked from 140bytes/LICENSE.txt
Complete jquery css method clone

A perfect replica (hopefully) of the jQuery .css() method

testNode.css("color","blue")   //use it with two string arguments!

testNode.css({color:"red"})    //use it with an object!

testNode.css("color")          //make it return the value of a property

It's even chainable!

@williammalo
williammalo / README.md
Last active March 8, 2018 11:52 — forked from 140bytes/LICENSE.txt
get query variable

use like this:

getQueryVariable("foo")

To get variables in urls eg:

http://foo.com/index.html?foo=bar

If you want to support arrays, check the version by @atk below:

@williammalo
williammalo / README.md
Last active March 8, 2018 11:58 — forked from 140bytes/LICENSE.txt
BoxCollisionCheck

Function to check if 2 objects collide. Very useful for games.

arguments:

a: object 1 x

b: object 1 y

@williammalo
williammalo / README.md
Last active March 28, 2018 16:18 — forked from 140bytes/LICENSE.txt
jquery animate clone

A clone of the jquery animate function for NEW BROWSERS ONLY!

For now, you need to add a vendor prefix for it to work, but it will work in future browsers just fine.

To use the function, add it as an element prototype and use it just like you would use the jquery animate function:

element.animate(properties,duration,callback)

Also, I am aware that my coding skills suck a bit =)