This is a fork of the awesome chainify library (https://gist.github.com/gists/1466219).
I made it because I don't like with().
bonus: It's much faster! http://jsperf.com/chaining-mehods
demo here: http://jsfiddle.net/ce25R/3/
This is a fork of the awesome chainify library (https://gist.github.com/gists/1466219).
I made it because I don't like with().
bonus: It's much faster! http://jsperf.com/chaining-mehods
demo here: http://jsfiddle.net/ce25R/3/
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)
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!
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:
Function to check if 2 objects collide. Very useful for games.
arguments:
a: object 1 x
b: object 1 y
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 =)
This function loops through all images on the page, and serves the appropriately sized image file from a list in a data attribute.
example link: http://total.maloweb.com/responsive
example html:
<img src="default.png" data-widths="400,600,800,1023" data-srcsuffix="-foo.png">
example javascript:
I always found it strange that when you set the font size to 50% in css, letters don't take 50% of the width of the page.
This script makes text behave in that way.
converts canvas image data to a 2d array of booleans
array=img2array(imagedata,width,height)
array[x][y] //gives true or false
very useful for games where you need pixel perfect collision.
Reading an image every time you check for collision is slow. Using a 2d array makes it much faster, and has a very simple syntax (array[x][y]) .