Skip to content

Instantly share code, notes, and snippets.

View Dexdot's full-sized avatar
🏠
Working from home

Kam Dexdot

🏠
Working from home
View GitHub Profile
@Dexdot
Dexdot / parallax.js
Created July 16, 2019 10:11
animations on scroll
const math = {
map: (x, a, b, c, d) => ((x - a) * (d - c)) / (b - a) + c,
lerp: (a, b, n) => (1 - n) * a + n * b
};
const { body } = document;
// Window
let winsize;
const calcWinsize = () => {
winsize = { width: window.innerWidth, height: window.innerHeight };
@Dexdot
Dexdot / jq.viewport.js
Created May 14, 2018 13:49
jQuery viewport checker
$.fn.isInViewport = function() {
const elementTop = $(this).offset().top;
const elementBottom = elementTop + $(this).outerHeight();
const viewportTop = $(window).scrollTop();
const viewportBottom = viewportTop + $(window).height();
return elementBottom > viewportTop && elementTop < viewportBottom;
};
@Dexdot
Dexdot / datediff.js
Created May 5, 2018 08:20
Date difference
class DateDiff {
constructor(date1, date2) {
this.days = null;
this.hours = null;
this.minutes = null;
this.seconds = null;
this.date1 = date1;
this.date2 = date2;
this.init();
}
@Dexdot
Dexdot / cookie.ts
Created November 28, 2021 15:51
Cookie TS
@Dexdot
Dexdot / cookie.js
Created November 28, 2021 15:50
Cookie JS
function createDateAsUTC(date) {
return new Date(Date.UTC(date.getFullYear(), date.getMonth(), date.getDate(), date.getHours(), date.getMinutes(), date.getSeconds()));
}
function convertDateToUTC(date) {
return new Date(date.getUTCFullYear(), date.getUTCMonth(), date.getUTCDate(), date.getUTCHours(), date.getUTCMinutes(), date.getUTCSeconds());
}
import { useEffect } from 'react';
import { Provider } from 'react-redux';
import { BrowserRouter as Router } from 'react-router-dom';
import { ThemeProvider } from '@material-ui/core/styles';
import CssBaseline from '@material-ui/core/CssBaseline';
import { Routes } from '@/components/Routes';
import { theme } from '@/styles/theme';
import { store } from '@/store/store';
@Dexdot
Dexdot / useScrollBottom.ts
Created February 16, 2021 21:35
Scroll on bottom (React<TS>)
import { useRef, useEffect, useState, useCallback } from 'react';
interface ReturnDataI {
ref: React.MutableRefObject<Element | null>;
isBottom: boolean;
}
export function useScrollBottom(offset = 0): ReturnDataI {
const ref = useRef<Element>(null);
const [isBottom, setIsBottom] = useState<boolean>(false);
export async function getImageUrl(file: File): Promise<string | ArrayBuffer> {
return new Promise((resolve) => {
import('exif-js')
.then((EXIF) => {
EXIF.getData(file, function onGetData() {
const reader = new FileReader();
reader.onload = ({ target }) => {
resolve(target.result);
};
reader.readAsDataURL(this);
import IMask from 'imask';
export default class Input {
constructor(el) {
this.el = el;
this.input = $.qs('.input__field', this.el);
this.isDate = this.input.type === 'date';
this.isPhone = this.input.type === 'tel';
this.isMaskDate = this.input.classList.contains('js-mask-date');