What do you want to save?
Add Code snippet
New code examples
-
Other 2021-10-01 02:33:04
how to disable up and down arrow downscroll for a website
var keys = {}; window.addEventListener("keydown", function(e){ keys[e.keyCode] = true; switch(e.keyCode){ case 37: case 39: case 38: case 40: // Arrow keys case 32: e.preventDefault(); break; // Space... Add solution -
Other 2021-09-29 03:42:03
debounce
// Returns a function, that, as long as it continues to be invoked, will not // be triggered. The function will be called after it stops being called for // N milliseconds. If `immediate` is passed, trigger the function on the // leading edge, instead of ... Add solution -
Javascript 2021-09-28 05:45:02
react pdf add to existing pdf
import React, { PureComponent } from "react" import { Document, Page } from "react-pdf/build/entry.webpack" import throttle from "lodash.throttle" import pdf from "./pdf.pdf" class App extends PureComponent { con... Add solution -
Javascript 2021-09-28 04:54:03
make event listener trigger on two things
// Setup our function to run on various events var someFunction = function (event) { // Do something... }; // Add our event listeners window.addEventListener('click', someFunction, false); window.addEventListener('mouseover', someFunction, false); Add solution -
Javascript 2021-09-27 18:47:02
js document ready
//two ways of executing JS code after page is loaded, use "DOMContentLoaded" when able document.addEventListener("DOMContentLoaded", function(){ //dom is fully loaded, but maybe waiting on images & css files }); window.... Add solution -
Javascript 2021-09-27 13:45:02
Detecting clicks outside of an element (or inside)
window.addEventListener('mousedown', e => { // Get the element that was clicked const clickedEl = e.target; // `el` is the element you're detecting clicks outside of if (el.contains(clickedEl)) { // Clicked inside of `el` } else { //... Add solution -
Javascript 2021-09-27 09:56:05
scroll down up js
var lastScrollTop = 0; // element should be replaced with the actual target element on which you have applied scroll, use window in case of no target element. element.addEventListener("scroll", function(){ // or window.addEventListener("sc... Add solution -
Javascript 2021-09-24 16:43:05
js catch errors on listeners
// If you would like to access errors thrown from event handlers, // you may listen to the error event on window. // It will be emitted for all uncaught errors in the current JavaScript VM: window.addEventListener('error', function(event) { console.log... Add solution
Best helpers
Ranking is empty