Skip to content

Instantly share code, notes, and snippets.

View ncou's full-sized avatar
🪲
Catching bugs !

ncou

🪲
Catching bugs !
View GitHub Profile
@ncou
ncou / hnl.isVisible.js
Created July 2, 2017 08:49 — forked from c-kick/hnl.isVisible.js
hnl.isVisible.js - jquery extension to check if an element is visible in the browser's viewport
$.fn.isVisible = function() {
// Am I visible?
// Height and Width are not explicitly necessary in visibility detection, the bottom, right, top and left are the
// essential checks. If an image is 0x0, it is technically not visible, so it should not be marked as such.
// That is why either width or height have to be > 0.
var rect = this[0].getBoundingClientRect();
return (
(rect.height > 0 || rect.width > 0) &&
rect.bottom >= 0 &&
rect.right >= 0 &&
@ncou
ncou / preloader.js
Created August 6, 2017 09:17 — forked from rlemon/preloader.js
image preloader
function preload(list, callback, imageCallback) {
var at = len = list.length;
return list = list.map(function (item) {
var pItem = new Image();
pItem.onload = function (i) {
imageCallback && imageCallback.call(this, this, len-at, len);
if (!--at) {
callback(list);
}
};
@ncou
ncou / jquery.debounce.js
Created August 8, 2017 21:31 — forked from evanre/debounce-throttle.js
Debounce and throttle function's decorator jQuery plugin
/**
* Debounce and throttle function's decorator plugin 1.0.5
*
* Copyright (c) 2009 Filatov Dmitry ([email protected])
* Dual licensed under the MIT and GPL licenses:
* http://www.opensource.org/licenses/mit-license.php
* http://www.gnu.org/licenses/gpl.html
* https://habrahabr.ru/post/60957/
*
*/
@ncou
ncou / inherit.js
Created August 17, 2017 13:03 — forked from iptpv/inherit.js
Yet another inherit library.
var extend = function(target, source) {
for (var i in source) {
if (source.hasOwnProperty(i)) {
target[i] = source[i];
}
}
return target;
};
var objectCreate = function(ParentProto, ChildProto) {
@ncou
ncou / inherit
Created August 17, 2017 13:06 — forked from Moncader/gist:3521832
JS Class Style Inheriting
function inherit(pThis, pBase) {
pThis.prototype = Object.create(pBase.prototype);
pThis.prototype.constructor = pThis;
pThis.prototype.super = pBase.prototype;
}
function Animal() {
this.type = 'animal';
this.num = 34;
}
@ncou
ncou / draggable popup app.js
Created August 30, 2017 10:22 — forked from akirattii/app.js
Draggable & Movable popup example using pure javascript.
(function(){
var SCROLL_WIDTH = 24;
var btn_popup = document.getElementById("btn_popup");
var popup = document.getElementById("popup");
var popup_bar = document.getElementById("popup_bar");
var btn_close = document.getElementById("btn_close");
var smoke = document.getElementById("smoke");
@ncou
ncou / throttle
Created September 5, 2017 05:33 — forked from simmo/throttle.js
JavaScript Throttle using requestAnimationFrame
function throttle(type, name, obj) {
var running = false;
obj = obj || window;
var func = function() {
if (running) return;
running = true;
@ncou
ncou / color_luminance.php
Created September 7, 2017 21:18 — forked from stephenharris/color_luminance.php
Lighten or darken a given colour
<?php
/**
* Lightens/darkens a given colour (hex format), returning the altered colour in hex format.7
* @param str $hex Colour as hexadecimal (with or without hash);
* @percent float $percent Decimal ( 0.2 = lighten by 20%(), -0.4 = darken by 40%() )
* @return str Lightened/Darkend colour as hexadecimal (with hash);
*/
function color_luminance( $hex, $percent ) {
// validate hex string
@ncou
ncou / Media Query CSS
Created October 9, 2017 21:17 — forked from dhamaso/Media Query CSS
Media Query CSS Template
/*=====================================================
Twitter Bootstrap
=====================================================*/
/* Large desktop */
@media (min-width: 1200px) { ... }
/* Portrait tablet to landscape and desktop */
@media (min-width: 768px) and (max-width: 979px) { ... }
/* Landscape phone to portrait tablet */
@ncou
ncou / media-query.css
Created October 9, 2017 21:18 — forked from gokulkrishh/media-query.css
CSS Media Queries for Desktop, Tablet, Mobile.
/*
##Device = Desktops
##Screen = 1281px to higher resolution desktops
*/
@media (min-width: 1281px) {
//CSS