Skip to content

Instantly share code, notes, and snippets.

@severuykhin
severuykhin / count.js
Last active January 24, 2017 15:51
Script fo animated counters and onetime called function
function countDown(start, end, item) {
var startFrom = start;
var timer = setInterval(function(){
startFrom += 1;
item.innerHTML = startFrom;
if(startFrom >= end){clearInterval(timer)}
}, 10);
}
@severuykhin
severuykhin / debounce.js
Created April 2, 2017 12:29
Converts several function calls within a certain time into one call
var debounce = function (f, ms){
var state = null;
var COOLDOWN = 1;
return function(){
if(state) return;
f.apply(this. arguments);
@severuykhin
severuykhin / OOP1.js
Created April 2, 2017 13:33
JavaScript OOP examples
function CoffeMachine(power){
const _this = this; //Сохранение контекста для обрращения к нему из внутренних функций
//Set water amount
this.waterAmount = 0;
const WATER_HEAT_CAPACITY = 4200;
var timerId;
@severuykhin
severuykhin / OOP2.js
Created April 2, 2017 15:03
JavaScript OOP examples w
//Coffie machine constructor
//===================================================================
function CoffeMachine(power, capacity){
//Define private vars //Сохранение контекста для обрращения к нему из внутренних функций
const WATER_HEAT_CAPACITY = 4200;
const POWER = power;
var timerId;
@severuykhin
severuykhin / OOP3.js
Created April 2, 2017 19:19
JavaScript OOP example 3
//Prototype inheritance
//===================================================================
function Machine (power) {
var self = this;
self._enabled = false;
this._power = power;
@severuykhin
severuykhin / cookie.js
Created April 8, 2017 22:12
get cookie
@severuykhin
severuykhin / scroll.js
Created May 14, 2017 11:37
Scroll detection
$('element').bind('DOMMouseScroll mousewheel', function(e){
event.preventDefault();
if(e.originalEvent.wheelDelta > 0 || e.originalEvent.detail < 0) {
//Actions
}
else{
//Actions
}
});
@severuykhin
severuykhin / nav.js
Created June 3, 2017 09:12
Dynamic navigation
(function($){
//Get elements
var sections = $('section'),
menuItems = $('.sidenav-item'),
sectionsPosition = [],
itemsValues = {};
//Get sections positions from top
for (var i = 0, length = sections.length; i < length; i++) {
@severuykhin
severuykhin / gulp.txt
Created June 21, 2017 20:10
gulp tips
1.laze require =>
Ленивая загрузка модулей - при загрузке отсутствующего модуля, lazyequire загрузит его
gulp_tasks/config/index.js - лежит основной конфиг проета
@severuykhin
severuykhin / Patterns.js
Created June 25, 2017 17:54
JavaScript patterns practice
/*********************************************
*
* Strategy
*
**********************************************/
const weapons = {
sword: {
'name': 'Excalibur',
'damage': 20