Skip to content

Instantly share code, notes, and snippets.

@sergeh
sergeh / media_query_interactions.css
Created July 19, 2020 05:49
Media queries for different types of devices
@media (hover: none) and (pointer: coarse) {
/* you're on a touch-only device */
}
@media (hover: none) and (pointer: fine) {
/* you're on a device without hover but with a stylus
or other fine pointing device */
}
@media (hover: hover) and (pointer: coarse) {

Gmail and GitHub

Create new filters and create new labels.

Pull Request

from:([email protected]) AND {"Patch Links" "approved this pull request." "requested changes on this pull request." "commented on this pull request." "pushed /d+ commit."}

label: gh-pull-request

@sergeh
sergeh / app.js
Created October 29, 2019 18:15
Stop animations on resize
let resizeTimer;
window.addEventListener("resize", () => {
document.body.classList.add("resize-animation-stopper");
clearTimeout(resizeTimer);
resizeTimer = setTimeout(() => {
document.body.classList.remove("resize-animation-stopper");
}, 400);
});
@sergeh
sergeh / alt_debug.css
Created November 20, 2017 15:38
Display images with empty or forgotten alt attributes
img[alt=""],
img:not([alt]) {
border: 5px dashed #c00;
}
@sergeh
sergeh / intersection-observer.js
Created August 11, 2017 18:19
Intersection Observer - Image lazy load
// Get all of the images that are marked up to lazy load
const images = document.querySelectorAll('.js-lazy-image');
const config = {
// If the image gets within 50px in the Y axis, start the download.
rootMargin: '50px 0px',
threshold: 0.01
};
// The observer for the images on the page
let observer = new IntersectionObserver(onIntersection, config);
@sergeh
sergeh / background-svg.scss
Created December 9, 2016 22:30
Insert an svg as a background image and be able to modify its fill
@function str-replace($string, $search, $replace: '') {
$index: str-index($string, $search);
@if $index {
@return str-slice($string, 1, $index - 1) + $replace + str-replace(str-slice($string, $index + str-length($search)), $search, $replace);
}
@return $string;
}
@sergeh
sergeh / decode.css
Created September 15, 2016 19:13
jQuery Decode effect
body { font-family: monospace; }
.code { color: red; }
@sergeh
sergeh / isElementInViewport.js
Created August 15, 2016 18:22
Check if element is fully in viewport
function isElementInViewport (el) {
if (typeof jQuery === "function" && el instanceof jQuery) {
el = el[0];
}
var rect = el.getBoundingClientRect();
return (
rect.top >= 0 &&
rect.left >= 0 &&
@sergeh
sergeh / 0_reuse_code.js
Created August 13, 2014 03:28
Here are some things you can do with Gists in GistBox.
// Use Gists to store code you would like to remember later on
console.log(window); // log the "window" object to the console