Skip to content

Instantly share code, notes, and snippets.

import { useState, useEffect } from 'react';
const useWindowSize = () => {
// IMPLEMENT
const [size, setSize] = useState({width: window.innerWidth, height: window.innerHeight});
useEffect(() => {
const eventResize = () => {
setSize({width: window.innerWidth, height: window.innerHeight});
}
window.addEventListener('resize', eventResize);
@0632347878
0632347878 / Retina images
Created October 2, 2016 11:46
Specify two image paths and the @1x image dimensions, and Bootstrap will provide an @2x media query. If you have many images to serve, consider writing your retina image CSS manually in a single media query.
.img-retina(@file-1x; @file-2x; @width-1x; @height-1x) {
background-image: url("@{file-1x}");
@media
only screen and (-webkit-min-device-pixel-ratio: 2),
only screen and ( min--moz-device-pixel-ratio: 2),
only screen and ( -o-min-device-pixel-ratio: 2/1),
only screen and ( min-device-pixel-ratio: 2),
only screen and ( min-resolution: 192dpi),
only screen and ( min-resolution: 2dppx) {
.element {
position: relative;
}
/*replace the content value with the
corresponding value from the list below*/
.element:before {
content: "\f000";
font-family: FontAwesome;
@0632347878
0632347878 / README.md
Created December 23, 2020 15:11 — forked from joyrexus/README.md
Vanilla JS equivalents of jQuery methods

Sans jQuery

Events

// jQuery
$(document).ready(function() {
  // code
})
$('.js-anchor').click(function () {
$('html, body').animate({
scrollTop: $($.attr(this, 'href')).offset().top - 50
}, 500);
});
$('html, body').animate({
scrollTop: $("#target-element").offset().top
}, 1000);
$('a').click(function(){
let href = $(this).attr('href'),
elem = $(href).offset().top;
$('html, body').animate({scrollTop: elem}, 500);
case 1
// console.log(value.slice(5, 7));
// if(value.slice(5, 7).includes('67'||'96'||'97'||'68'||'98'||'39'||'50'||'99'||'66'||'95'||'63'||'93'||'73')) {
// console.log('yyyyyyyyyyyyyyyyes');
// }
/**
* For accept the lazy loading to images you need just add
* [data-lazy-src] with a path on image.
*/
export default (window.onload = () => {
const images = document.querySelectorAll('[data-lazy-src]');
if ('IntersectionObserver' in window) {
let observer = new IntersectionObserver(
@0632347878
0632347878 / gist:e96525c56afa72735aa33692e6d55d1e
Created February 5, 2020 16:24
Scroll to loacation hash
RIGHT
if (window.location.hash) {
$('html, body').animate({
scrollTop: $(window.location.hash).offset().top - 50
}, 500);
}
WRONG
// let url = location.href;
@0632347878
0632347878 / gist:b2f967ab2b5ab1f13e2b8356bf83ea36
Created February 5, 2020 09:19
Polyfill for IE11 missing NodeList.forEach
if ('NodeList' in window && !NodeList.prototype.forEach) {
console.info('polyfill for IE11');
NodeList.prototype.forEach = function (callback, thisArg) {
thisArg = thisArg || window;
for (var i = 0; i < this.length; i++) {
callback.call(thisArg, this[i], i, this);
}
};
}