Skip to content

Instantly share code, notes, and snippets.

View iamchristough's full-sized avatar

Chris Tough iamchristough

View GitHub Profile
@iamchristough
iamchristough / password-reveal.js
Created February 13, 2019 16:58
Password Reveal React component
class PasswordRevealer extends React.Component {
constructor(props) {
super(props);
this.state = {
shown: false
};
this.toggleShown = this.toggleShown.bind(this);
}
toggleShown() {
@iamchristough
iamchristough / getMousePos.js
Created February 14, 2019 10:49
Get a users mouse position
let winsize;
const calcWinsize = () => winsize = {width: window.innerWidth, height: window.innerHeight};
calcWinsize();
window.addEventListener('resize', calcWinsize);
const getMousePos = (ev) => {
let posx = 0;
let posy = 0;
if (!ev) ev = window.event;
if (ev.pageX || ev.pageY) {
@iamchristough
iamchristough / mapElements.js
Last active February 14, 2019 10:50
Map elements and elements default positions to an array
const imgs = [...document.querySelectorAll('.content__img')];
const imgsTotal = imgs.length;
let imgTranslations = [...new Array(imgsTotal)].map(() => ({x: 0, y: 0}));
@iamchristough
iamchristough / randomHex.js
Created February 14, 2019 12:07
Generate a random hex code
const randomHexColorCode = () => {
let n = (Math.random() * 0xfffff * 1000000).toString(16);
return '#' + n.slice(0, 6);
};
@iamchristough
iamchristough / buffer-loader.js
Created March 13, 2019 14:12
Buffer load Media files
function BufferLoader(context, urlList, callback) {
this.context = context;
this.urlList = urlList;
this.onload = callback;
this.bufferList = new Array();
this.loadCount = 0;
}
BufferLoader.prototype.loadBuffer = function(url, index) {
var request = new XMLHttpRequest();
"browserify": {
"transform": [["babelify", { "presets": ["es2015", "stage-0"] }]]
},
@iamchristough
iamchristough / svg-icon-component.js
Created May 24, 2019 10:07
svg-icon-component.js
import React, { Component } from 'react'
import cx from 'classnames'
import PropTypes from 'prop-types'
import Instagram from '../../../static/images/instagram.svg'
import Story from '../../../static/images/story.svg'
import Facebook from '../../../static/images/facebook.svg'
import Twitter from '../../../static/images/twitter.svg'
import Snapchat from '../../../static/images/snapchat.svg'
import Youtube from '../../../static/images/youtube.svg'
import Blog from '../../../static/images/blog.svg'
let renderer, camera, controls, scene,
width = window.innerWidth,
height = window.innerHeight;
init();
animate();
render();
function init() {
// RENDERER
@iamchristough
iamchristough / animatedScrollTo.js
Created April 1, 2020 12:03 — forked from joshbeckman/animatedScrollTo.js
ScrollTo animation using pure javascript and no jquery
document.getElementsByTagName('button')[0].onclick = function () {
scrollTo(document.body, 0, 1250);
}
function scrollTo(element, to, duration) {
var start = element.scrollTop,
change = to - start,
currentTime = 0,
increment = 20;
@iamchristough
iamchristough / hideCursor.js
Created May 11, 2020 11:23
Hide Cursor on idle
(function() {
var mouseTimer = null, cursorVisible = true;
function disappearCursor() {
mouseTimer = null;
document.body.style.cursor = "none";
cursorVisible = false;
}
document.onmousemove = function() {