Skip to content

Instantly share code, notes, and snippets.

View iamklim's full-sized avatar

Vladyslav Klymenko iamklim

View GitHub Profile
function axelerateBackground(bgWrapperHeight) {
var $bgWrapper = $('.bg_wrapper'); //parallax block inside body with position fixed and css background
$(document).on('scroll', function() {
var dHeight = $(document).height(),
wHeight = $(window).height(),
imgHeight = bgWrapperHeight ? bgWrapperHeight : $bgWrapper.height(), //height of parallax block
coeff = (imgHeight - wHeight) / (dHeight - wHeight); //coefficient to avoid empty spaces on background
var shift = -1 * ($(window).scrollTop() * coeff); //size of shift on the top
@iamklim
iamklim / togglePopup.js
Created May 13, 2019 10:24
Show popup without overflow:hidden, page jumping and toggling
function togglePopup() {
var scrollPosition;
$(document).on("click", '[data-id="show-popup"]', function(e) {
e.preventDefault();
var popup = '[data-id="popup"]';
scrollPosition = $('body').scrollTop() === 0
@iamklim
iamklim / throttle.js
Created June 5, 2022 20:16
Simple ES6 throttle
const throttle = (func, ms) => {
let isThrottled = false;
return (...args) => {
if (!isThrottled) {
func(...args);
isThrottled = true;
setTimeout(() => {