This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/* | |
instead of declaring global variables. | |
var counter = 0; | |
$(document).on("click", function(){ | |
console.log(counter); | |
counter++; | |
}); | |
*/ | |
$(document).on("click", function handler(){ |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/* Solution 0: | |
* Avoiding line breaks in code or using multi-line comments as placeholders for line-breaks. | |
* Its best to adopt this solution if its part of the html build process to remove whitespaces. | |
*/ | |
/* Solution 1: | |
* use width=device-width (needed for iphone). | |
*/ | |
.list-wrapper { | |
letter-spacing: -0.31em; /* -4px doesnt work in zoomed states */ |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
a{ | |
line-height:0; | |
/*font-size:0; will not work only line-height*/ | |
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/* Solution 1 (best) */ | |
.wrap{ | |
position:relative; | |
} | |
img{ | |
position:abosulute; | |
top:0; | |
right:0; | |
bottom:0; | |
left:0; |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/** crop vertical portions **/ | |
.outer-wrap{ | |
position:relative; | |
width:100px; | |
height:100px; /* @OH */ | |
background:#ccc; | |
overflow:hidden; | |
} | |
.inner-wrap{ |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// Returns a function, that, as long as it continues to be invoked, will not | |
// be triggered. The function will be called after it stops being called for | |
// N milliseconds. If `immediate` is passed, trigger the function on the | |
// leading edge, instead of the trailing. | |
function debounce(func, wait, immediate) { | |
var timeout; | |
return function() { | |
var context = this, args = arguments; | |
var later = function() { | |
timeout = null; |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
(function($) { | |
$.extend({ | |
debounce : function(fn, timeout, invokeAsap, ctx) { | |
if(arguments.length == 3 && typeof invokeAsap != 'boolean') { | |
ctx = invokeAsap; | |
invokeAsap = false; | |
} | |
var timer; | |
return function() { | |
var args = arguments; |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
function throttle(fn, threshhold, scope) { | |
threshhold || (threshhold = 250); | |
var last, | |
deferTimer; | |
return function () { | |
var context = scope || this; | |
var now = +new Date, | |
args = arguments; | |
if (last && now < last + threshhold) { |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
(function($) { | |
$.extend({ | |
throttle : function(fn, timeout, ctx) { | |
var timer, args, needInvoke; | |
return function() { | |
args = arguments; | |
needInvoke = true; | |
ctx = ctx || this; | |
if(!timer) { | |
(function() { |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// just typepof myVar == 'string' fails when my var is declared => var myVar = new String("value"); | |
if (typeof myVar == 'string' || myVar instanceof String){ | |
// it's a string | |
} | |
// just typepof myVar == 'string' fails when my var is declared => var myVar = new String("value"); | |
if (typeof myVar == 'number' || myVar instanceof Number){ | |
// it's a string | |
} |