Skip to content

Instantly share code, notes, and snippets.

@nola
nola / operators.js
Created November 26, 2013 01:40
JS operators shorthand
x=x+1;
minusCount = minusCount - 1;
y=y*10;
//shorthand version
x++;
minusCount --;
y*=10;
@nola
nola / variableShorthand.js
Created November 26, 2013 01:38
Declaring variables Shorthand
var x;
var y;
var z = 3;
//shorthand
var x, y, z=3;
@nola
nola / assoicativearray.js
Created November 26, 2013 01:36
The old school way of setting up an array was to create a named array and then add each named element one by one. A quicker and more readable way is to add the elements at the same time using the object literal notation. Please note that Associative Array are essentially JavaScript Objects with properties.
var skillSet = new Array();
skillSet['Document language'] = 'HTML5';
skillSet['Styling language'] = 'CSS3';
skillSet['Javascript library'] = 'jQuery';
skillSet['Other'] = 'Usability and accessibility';
//short hand version
var skillSet = {
'Document language' : 'HTML5',
'Styling language' : 'CSS3',
@nola
nola / shortarray.js
Created November 26, 2013 01:35
Useful way of declaring small arrays on one line. Object Array Notation Shorthand
var a = new Array();
a[0] = "myString1";
a[1] = "myString2";
a[2] = "myString3";
//short hand version
var a = ["myString1", "myString2", "myString3"];
@nola
nola / null.js
Created November 26, 2013 01:33
Null, Undefined, Empty Checks Shorthand When creating new variables sometimes you want to check if the variable your referencing for it’s value isn’t null or undefined. I would say this is a very common check for JavaScript coders.
if (variable1 !== null || variable1 !== undefined || variable1 !== '') {
var variable2 = variable1;
}
//short hand
var variable2 = variable1 || '';
@nola
nola / ifelseshorthand.js
Created November 26, 2013 01:31
If true … else Shorthand
var big;
if (x > 10) {
big = true;
}
else {
big = false;
}
//Short hand version
var big = (x > 10) ? true : false;
@nola
nola / js-for-loop.js
Created November 26, 2013 01:12
javascript for loop
var myLinkCollection = document.getElementsByTagName("a");
for (i=0;i<myLinkCollection.length;i++) {
if (myLinkCollection[i].getAttribute("href")) {
// do something with the anchor tags here
}
}
@nola
nola / jquery-on-off.js
Last active December 29, 2015 09:28
example of jquery on and off, similar to bind and unbind
$(function() {
$(window).on("mousemove", mouseMoveHandler);
function mouseMoveHandler(e) {
var pos = e.clientY;
console.log(pos);
if (pos < 15) {
//key take away, is once you've got the event you want to trigger, it's good to "Turn OFF" the listner
$(window).off( "mousemove", mouseMoveHandler );
$(".footer-popup").animate({
bottom: 0
@nola
nola / gist:7649251
Created November 25, 2013 21:32
Console log mouse position clientY shows the Y value in pixels The second one shows event data for mousemove
$(window).on("mousemove", function (e) { console.log(e.clientY) });
$(window).on("mousemove", function (e) { console.log(e) });
@nola
nola / css
Created October 14, 2013 15:18
Scrolling background
.fullWH{
width: 100%;
height: 323px;
}
#bg1 {
background-image: url( "../img/bg1.png" );
}
#bg2 {
background-image: url( "../img/bg2.png" );
}