Skip to content

Instantly share code, notes, and snippets.

// Mobile Navigation
$('.nav-toggle').on('click', function() {
$(this).toggleClass('close-nav');
nav.toggleClass('open');
return false;
});
nav.find('a').on('click', function() {
$('.nav-toggle').toggleClass('close-nav');
nav.toggleClass('open');
});
// Page Scroll
var sections = $('section')
nav = $('nav[role="navigation"]');
$(window).on('scroll', function () {
var cur_pos = $(this).scrollTop();
sections.each(function() {
var top = $(this).offset().top - 76
bottom = top + $(this).outerHeight();
if (cur_pos >= top && cur_pos <= bottom) {
http://stackoverflow.com/questions/3656592/how-to-programmatically-disable-page-scrolling-with-jquery
http://jsbin.com/ikuma4/2/edit?html,js,output
function numericValue(event) {
var e = event || window.event;
var code = e.keyCode || e.which;
// allow backspace, delete, tab, and all four arrows
var controlKeys = [8, 9, 46];
var inputField = e.target || e.srcElement;
// IE doesn't support indexOf
var isControlKey = controlKeys.join(",").match(new RegExp(code));
// Some browsers just don't raise events for control keys. Easy.
// e.g. Safari backspace.
@oleksapro
oleksapro / get all attr
Last active September 25, 2015 10:33
js. jquery
// http://stackoverflow.com/questions/14645806/get-all-attributes-of-an-element-using-jquery
/**
* Получить все атрибуты
*/
(function(old) {
$.fn.attr = function() {
if (arguments.length === 0) {
if (this.length === 0) {
return null;
@oleksapro
oleksapro / slider
Created October 1, 2015 19:26
js, slider
http://jsfiddle.net/aN8zc/
/**
* Detect which transition event browser supported
* @returns {*}
*/
var whichTransitionEvent = function () {
var t;
var el = document.createElement('fakeelement');
var transitions = {
'WebkitTransition': 'webkitTransitionEnd',
'transition': 'transitionend',
@oleksapro
oleksapro / load content in bpopup
Last active October 22, 2015 09:43
js, bpopup
$('.banners__item').click(function () {
var src = $(this).find('img').attr('src');
var bannerSrc = 'img/banners/big/240x400' + src.replace(/img\/banners/, '');
$('.popup__wrap__img').attr('src', bannerSrc);
$('.popup').bPopup({
speed: 300,
followSpeed: 200,
closeClass: 'popup__cross'
});
});
@oleksapro
oleksapro / prevent move on mobile
Last active October 27, 2015 14:14
js, jquery, mobile
// http://stackoverflow.com/questions/17068026/prevent-ios-safari-from-moving-web-page-window-so-drag-event-can-happen
$(window).bind(
'touchmove',
function(e) {
e.preventDefault();
}
);
// https://github.com/gulpjs/gulp/blob/master/docs/API.md#gulpsrcglobs-options
// http://stackoverflow.com/questions/23384239/excluding-files-directories-from-gulp-task
fonts: ['./src/fonts/**/*.*', '!./src/fonts/icons/svg/*.*'],
// https://github.com/gulpjs/gulp/issues/165
gulp.src(['app/**', '!app/{_tmp,_tmp/**}'])
// http://stackoverflow.com/a/23793997/4142600
['dist/*, '!dist/scripts{,/vendor.js}'].